1

に取り組んでいる間MVVM in Silverlight 4.0。次の問題で行き詰まりました。
以下を参照してくださいXaml。また、TextBox1 ではメソッドUpdateText(インタラクション トリガーの下) が機能していますが、テンプレートTextBox2の一部であることに注意してください。メソッド ' ' はまったく機能していません。のイベントでメソッドを呼び出すのを手伝ってくれる人はいますか? (UpdateText は、TextBox2 ではなく、操作するクラスの単純なメソッドです)DataGrid'sUpdateTextTextChangedTextBox2MVVMTextBox1

xaml は次のとおりです。

<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="MVVMEventTriggerDemo.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModel="clr-namespace:MVVMEventTriggerDemo.ViewModels"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:si="clr-namespace:Expression.Samples.Interactivity;assembly=Expression.Samples.Interactivity"
Height="600" Width="700">
<UserControl.Resources>
    <viewModel:MainViewModel x:Key="MainViewmodel"/>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource MainViewmodel}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="258*" />
        <ColumnDefinition Width="262*" />
    </Grid.ColumnDefinitions>
    <TextBox x:Name="textbox1" Text="{Binding EmployeeName, Mode=TwoWay}" Width="100" Height="30" Margin="142,77,20,289" Grid.Column="1">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="TextChanged">
                <si:CallDataMethod Method="UpdateText"/>
                <si:ShowMessageBox Caption="Thank you"
                                   Message="Thanks for trying the Example"
                                   MessageBoxButton="OK"/>
                <si:SetProperty TargetName="textbox1" PropertyName="Background" Value="PaleGoldenrod"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </TextBox>
    <Button Content="Show Message" Width="100" Height="25" Margin="142,113,20,258" Grid.Column="1">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
                <si:CallDataMethod Method="HandleShowMessage"/>
                <si:ShowMessageBox Caption="Thank you"
                                   Message="Thanks for trying the Example"
                                   MessageBoxButton="OK"/>
                <si:SetProperty TargetName="LayoutRoot" PropertyName="Background" Value="PaleGoldenrod"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Button>
    <sdk:DataGrid 
        x:Name="dgDevice" 
        AutoGenerateColumns="False" 
        Margin="13,13,13,13"
        BorderThickness="1,0,1,1"
        RowBackground="White"
        VerticalScrollBarVisibility="Auto" Width="320" 
        Opacity="0.9"
        Background="White"
        GridLinesVisibility="None"
        HeadersVisibility="None"
        HorizontalScrollBarVisibility="Disabled"
        ItemsSource="{Binding ActualColors,Mode=TwoWay}">
        <sdk:DataGrid.Columns>
            <sdk:DataGridTemplateColumn Width="320" >
                <sdk:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Grid Width="auto">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="30*"  />                                   
                                <ColumnDefinition Width="20*" />
                            </Grid.ColumnDefinitions>

           <TextBox x:Name="textbox2" Text="{Binding EmployeeName, Mode=TwoWay}" Width="100" Height="30" Margin="142,77,20,289" Grid.Column="1">
            <i:Interaction.Triggers>
              <i:EventTrigger EventName="TextChanged">
                <si:CallDataMethod Method="UpdateText"/>
                <si:ShowMessageBox Caption="Thank you"
                                   Message="Thanks for trying the Example"
                                   MessageBoxButton="OK"/>
                <si:SetProperty TargetName="textbox2" PropertyName="Background" Value="PaleGoldenrod"/>
                 </i:EventTrigger>
               </i:Interaction.Triggers>
            </TextBox>
       </Grid>
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellTemplate>
            </sdk:DataGridTemplateColumn>
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>
</Grid>

4

1 に答える 1

0

それがあなたに役立つかどうかはわかりませんが、Datatemplateバインディングでは次のようになります

<TextBlock Text="{Binding Path=DataContext.BusyText, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />

上の文のテキストバインドと同じようにイベントをバインドする必要があるかもしれません。

于 2012-09-27T18:08:01.730 に答える