注:我使用Visual Studio 2012WPF数据模板和按钮
我有以下的DataTemplate(注:有一个TextBlock和Button)
<DataTemplate DataType="{x:Type ctlDefs:myButton}">
<StackPanel>
<TextBlock Text="{Binding LabelText}" Margin="10,0,10,0"/>
<Button Content="{Binding LabelText}" Margin="0,0,10,0"
Width="{Binding ButtonWidth}"
Height="35"
Command="{Binding ButtonCommand}"
Visibility="Visible"
/>
</StackPanel>
</DataTemplate>
我的屏幕动态添加myButton的控件到项控件
<ItemsControl ItemsSource="{Binding CommandButtons, Mode=OneWay}"
FlowDirection="LeftToRight"
DockPanel.Dock="Right"
>
我第一次渲染视图中,文本块显示为每个按键,但按键本身并没有。如果我隐藏视图并再次显示,则按钮有时会出现(如果CommandButton列表不更改,如果更改,则永不显示)。
渲染视图后,我查看了输出窗口并没有发生绑定错误。
我错过了什么。
这是否也发生,如果你不绑定按钮的宽度? ButtonWidth实现INotifyPropertyChanged吗? – LPL 2013-03-13 22:13:42
是的。如果我删除ButtonWidth,它的功能相同。从使用WPF检查器可以看出,按钮看起来像是在那里(为它保留的空间),并且当它显示出来时,所有属性都从第一个加载到第二个加载。 – adondero 2013-03-13 22:50:37