2012-04-18 4 views
0

여기서 mMaterialCentreGroupListView.xaml 파일에이 줄은 MaterialCentreGroupView으로 작성되었습니다. 하지만 viewmodel 속성에 액세스하기위한 데이터 컨텍스트를 볼 수 없습니다. 그것은 잘 작동하고 있습니다. 아래는 코드입니다.Datacontext가 지정되는 방법

<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}"/> 

일이 발생할 어떻게 바인딩 무엇인지 나에게 설명해주십시오보기?

답변

1

DataContext는 코드 숨김 파일 (.xaml 파일과 동일하지만 .cs 확장명의 파일)로 설정되어 있다고 가정합니다. DataContext = new SomeViewModel()과 같은 코드를 찾으십시오.

또는이 컨트롤을 다른 컨트롤에서 사용하는 경우 DataContext를 명시 적으로 설정할 수도 있고 그렇지 않은 경우 부모로부터 상속 될 수도 있습니다 (부모로부터 상속되거나 상속받지 않을 수도 있음). XAML 또는 코드 숨김에 명시 적으로 설정되지 않은 경우에도 마찬가지입니다. RESX 바인딩 및 사용법에 대한

+0

@StellerEleven를 참조하십시오 여기 materailcenterGroupListView.xaml에서이 줄을 지정하는 <폭스 바겐 : MaterialCentreGroupView의 DataContext = "{Binding SelectedMaterialCentreGroup}"/> 및 viewmodel에서 Public MaterialCentreGroupViewModel SelectedMaterialCentreGroup {return _selectedMaterialCentreGroup; }가 지정되었습니다. – pratikjgandhi

0

보기 'RESX'바인딩

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

자세한 내용은 아래의 링크를 Resx binding and usage

관련 문제