2016-11-02 5 views
0

私はこのコードを持っている:アクセス制御は8.1

<HubSection x:Name="MyHub"> 
    <DataTemplate> 
     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="*"></RowDefinition> 
       <RowDefinition Height="200"></RowDefinition> 
      </Grid.RowDefinitions> 
      <Image x:Name="MYImage" Source="{Binding image}" Height="50" Width="60" VerticalAlignment="Center"/> 
      <StackPanel Orientation="Vertical"> 
       <TextBlock TextWrapping="Wrap" Width="200" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding name}"/> 
       <Button Content="Click me"> 
      </StackPanel> 
     </Grid> 
    </DataTemplate> 
</HubSection> 

をしかし、私は背後にあるコードでは、テキストブロックの前景色を変更したい、テキストブロックにアクセスする方法がわかりません。

+0

を参照してください可能性があり

private void Page_Loaded(object sender, RoutedEventArgs e) { var hub_section = FindVisualChildByName<HubSection>(this.myHub, "myHubSection"); var text_box = FindVisualChildByName<WebView>(hub_section, "textbox1"); } public static T FindVisualChildByName<T>(DependencyObject parent, string name)where T : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) { var child = VisualTreeHelper.GetChild(parent, i); string controlName = child.GetValue(Control.NameProperty) as string; if (controlName == name) { return child as T; } else { T result = FindVisualChildByName<T>(child, name); if (result != null) return result; } } return null; } 

より詳細な情報あなたがプロパティに基づいて色の変化を引き起こすことができるので、あなたは、あなたのTextBlockにdatatriggersを追加することができますあなたのモデルで。 –

答えて

関連する問題