0

ここのmMaterialCentreGroupListView.xamlファイルでは、この行はMaterialCentreGroupView. しかし、ビューモデルのプロパティにアクセスするためのデータ コンテキストが表示されません。それはうまくいっています。以下はコードです。

<vw:MaterialCentreGroupView
            Style="{StaticResource DetailedViewStyle}"
            DataContext="{Binding SelectedMaterialCentreGroup}"/>

景色

<UserControl x:Class="MyBooks.View.MaterialCentreGroupView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
MinWidth="290" MaxWidth="290" Padding="20"
Background="#eee">

<UserControl.Resources>
    <ResourceDictionary Source="ViewResources.xaml" />
</UserControl.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Label
        Grid.Row="0" Grid.Column="0"
        Content="{Resx ResxName=MyBooks.Properties.Strings, Key=AccountCategoryListView_Name_Label}"
        HorizontalAlignment="Right"/>
    <TextBox
        x:Name="CategoryName"
        MaxLength="50"
        Style="{StaticResource FormControlStyle}"
        Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2"
        Text="{Binding Path=Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"/>

何が起こるのか、どのようにバインディングが発生するのか説明してください。

4

2 に答える 2

1

DataContextは、分離コード(.xamlファイルと同じ名前のファイルですが.cs拡張子が付いています)で設定されていると思います。DataContext = new SomeViewModel();のようなコードを探します。

または、このUserControlが別のコントロール内で使用されている場合は、DataContextを明示的に設定するか、そうでない場合は、親から継承します(親から継承する場合としない場合など)。 XAMLまたは分離コードのいずれにも明示的に設定されていません)。

于 2012-04-18T01:47:29.880 に答える
0

「Resx」バインディングを見てください

<Label 
    Grid.Row="0" Grid.Column="0" 
    Content="{Resx ResxName=MyBooks.Properties.Strings, Key=AccountCategoryListView_Name_Label}" 
    HorizontalAlignment="Right"/> 

resx バインディングと使用方法の詳細については、以下のリンクを参照してください Resx バインディングと使用方法

于 2012-04-18T01:54:56.753 に答える