Pergunta

I set the Text property of the Textbox control, and also i add an Interaction.Trigger to it. An exception is thrown When I try to parse the this XAML using XamlReader.Parse():

The xaml which i have is:

<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>

The exception message is: {"''Text' property has already been set on 'TextBox'.' Line number '1' and line position 'X'."}

line position points to the closing tag of TextBox </TextBox>

If I don't set any Interaction.Triggers it parses OK, but at least one Interaction.Triggers set, it throws the exception...

Can anyone give me some light on this please?

Foi útil?

Solução

The problem is with the xml:space="preserve" line in your TextBox declaration. If you'll drop it, it will parse as expected.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top