设置Text并添加Interaction.Triggers时出现奇怪的XAML Parse行为。 WPF

时间:2012-12-19 08:02:52

标签: c# wpf xaml xamlparseexception xamlreader

我设置文本框控件的文本属性,并且还向其添加了Interaction.Trigger。 当我尝试使用XamlReader.Parse()解析此XAML时抛出异常:

我拥有的xaml是:

<Grid xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"        
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Name="TopPanel" >
    <Grid.ColumnDefinitions>
        <ColumnDefinition />        
    </Grid.ColumnDefinitions>  
    <Grid.RowDefinitions>       
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>  
    <TextBox Name="TextBox_8241" FocusManager.IsFocusScope="True" Grid.Column="1" Grid.Row="1" xml:space="preserve" 
            Text="{Binding ppp, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">    
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseEnter">        
                    <cmd:EventToCommand PassEventArgsToCommand="True" Command="{Binding TextBox_8241_MouseEnterCommand}" />      
                </i:EventTrigger>    
            </i:Interaction.Triggers>  
    </TextBox>
</Grid>

异常消息是: {“''Text'属性已在'TextBox'上设置。'行号“1”和行位置“X”。“}

行位置指向TextBox的结束标记 </TextBox>

如果我没有设置任何Interaction.Triggers它解析OK,但至少设置了一个Interaction.Triggers,它会抛出异常......

有人可以对此给我一些启示吗?

1 个答案:

答案 0 :(得分:4)

问题在于TextBox声明中的xml:space="preserve"行。如果你放弃它,它将按预期解析。