Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight itemtemplate外部的Xaml绑定_Silverlight_Data Binding_Xaml - Fatal编程技术网

Silverlight itemtemplate外部的Xaml绑定

Silverlight itemtemplate外部的Xaml绑定,silverlight,data-binding,xaml,Silverlight,Data Binding,Xaml,我想绑定我的列表框的数据。想象一下我有这样的东西: <ListBox ItemsSource="{Binding MyList}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text={Binding Value} /> <TextBlock Text={Binding AbsoluteValue} /> </DataTe

我想绑定我的列表框的数据。想象一下我有这样的东西:

<ListBox ItemsSource="{Binding MyList}">
  <ListBox.ItemTemplate>
    <DataTemplate>
        <TextBlock Text={Binding Value} />
        <TextBlock Text={Binding AbsoluteValue} />
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>
但它不起作用

XAML:

<TextBlock x:Name="tbAbsoluteValue" Loaded="AbsoluteValue_Loaded" />

这是实现所需的一种方法,您也可以使用转换器,或者在
资源中为VM创建
静态资源
,并将其绑定为源。

事实上,这不是文本框,而是具有VisibilityProperty的StackPanel。我尝试过:private void StackPanel_Loaded(object sender,RoutedEventArgs e){StackPanel StackPanel=sender as StackPanel;StackPanel.SetBinding(StackPanel.VisibilityProperty,new Binding(“Loaded”){Source=DataContext,Mode=BindingMode.TwoWay}但它不起作用我假设你的虚拟机上加载的属性是布尔值?VisibilityProperty属于可见性类型。你需要一个转换器。(Bool to Visibility)哦,是的,忘了使用它:(stackPanel.SetBinding(stackPanel.VisibilityProperty,new Binding(“Loaded”){Source=DataContext,Mode=BindingMode.TwoWay,Converter=new VisibilityConverter());没问题:)谢谢
<TextBlock x:Name="tbAbsoluteValue" Loaded="AbsoluteValue_Loaded" />
void AbsoluteValue_Loaded(object sender, RoutedEventArgs e)
{
    TextBlock absoluteValue = sender as TextBlock;

    absoluteValue.SetBinding(TextBlock.TextProperty, new Binding("AbsoluteValue") { Source = VIEW_MODEL_OBJECT, Mode = BindingMode.TwoWay });
}