![](/img/trans.png)
[英]how to access variables in-behind xaml code from another in-behind xaml code
[英]How to access element (Combo Box) in XAML from code behind
如何访问XGrid中嵌套在GridViewColumn.CellTemplate
中的GridViewColumn.CellTemplate
? 通过访问组合框,我想在后面的代码中设置其ItemsSource
。
码:
<GridViewColumn Width="80">
<GridViewColumnHeader Content="UseCLUT"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=UseCLUT}" Style="{StaticResource GridBlockStyle}"/>
<ComboBox x:Name="combTrueFalse" SelectedItem="{Binding Path=UseCLUT}" Style="{StaticResource GridEditStyle}" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
我已将comboBox命名为combTrueFalse,并尝试在后面的代码中引用它,但找不到它。
我找到了解决该问题的方法。
我已将组合框的集合设置为一个类,其中包含用于combox选择的集合。
mainWindow类包含数据类的变量。
ItemsSource="{Binding ElementName=mainWindow, Path=data.comboxTFSmall}"
意思是说我已经将combox的项目设置为一个Class,该Class包含集合,而不是来自后面的代码。
<GridViewColumn Width="80" >
<GridViewColumnHeader Content="UseCLUT"/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=UseCLUT, Mode=TwoWay}" Style="{StaticResource GridBlockStyle}"/>
<ComboBox ItemsSource="{Binding ElementName=mainWindow, Path=data.comboxTFSmall}" SelectedValue="{Binding Path=UseCLUT}" Style="{StaticResource GridEditStyle}" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
如果发现我的解释有误导性的感谢,请纠正我。
问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.