数据模板中的数据绑定不起作用
我有 UserControl 对多个演示文稿进行过滤,而该演示文稿又具有 ContentControl。内容是各个演示文稿之间有所不同的单独过滤控件。
该方案在视觉上按预期工作,但数据绑定却不然。输出中没有数据绑定错误。 DataContext 来自一个名为 PimMasterVm 的视图模型,否则它看起来连接正确(即 5 个可用人员的状态等)
有人可以帮我解决这个问题吗?
干杯,
Berryl
过滤控件
<Grid>
<Border Style="{StaticResource FilterPanelBorderStyle}">
<StackPanel Orientation="Horizontal" x:Name="myFilterPanel" >
<ContentControl x:Name="ctrlFilters"
ContentTemplate="{Binding Path=FilterContentKey, Converter={StaticResource filterTemplateContentConv}}" />
<Button x:Name="btnClearFilter" Style="{StaticResource FilterPanelClearButtonStyle}" />
<Label x:Name="lblStatus" Style="{StaticResource FilterPanelLabelStyle}" Content="{Binding Status}" />
</StackPanel>
</Border>
</Grid>
数据模板(资源)
<DataTemplate x:Key="pimFilterContent">
<StackPanel Orientation="Horizontal" >
<cc:SearchTextBox x:Name="stbLastNameFilter"
Style="{StaticResource FilterPanelSearchTextBoxStyle}"
Text="{Binding Path=LastNameFilter, UpdateSourceTrigger=PropertyChanged}"
/>
<cc:SearchTextBox x:Name="stbFirstNameFilter"
Style="{StaticResource FilterPanelSearchTextBoxStyle}"
Text="{Binding Path=FirstNameFilter, UpdateSourceTrigger=PropertyChanged}"
/>
</StackPanel>
</DataTemplate>
I have UserControl to do filtering for several presentations, which in turn has a ContentControl. The content are the individual filtering controls that vary among the presentations.
The scheme works as intended visually, but the data bindings do not. There are no data binding errors in output. The DataContext is from a view model call PimMasterVm, which otherwise seems correctly wired (ie, the status of 5 avalable people, etc)
Can someone help me trouble shoot this?
Cheers,
Berryl
Filtering Control
<Grid>
<Border Style="{StaticResource FilterPanelBorderStyle}">
<StackPanel Orientation="Horizontal" x:Name="myFilterPanel" >
<ContentControl x:Name="ctrlFilters"
ContentTemplate="{Binding Path=FilterContentKey, Converter={StaticResource filterTemplateContentConv}}" />
<Button x:Name="btnClearFilter" Style="{StaticResource FilterPanelClearButtonStyle}" />
<Label x:Name="lblStatus" Style="{StaticResource FilterPanelLabelStyle}" Content="{Binding Status}" />
</StackPanel>
</Border>
</Grid>
Data Template (resource)
<DataTemplate x:Key="pimFilterContent">
<StackPanel Orientation="Horizontal" >
<cc:SearchTextBox x:Name="stbLastNameFilter"
Style="{StaticResource FilterPanelSearchTextBoxStyle}"
Text="{Binding Path=LastNameFilter, UpdateSourceTrigger=PropertyChanged}"
/>
<cc:SearchTextBox x:Name="stbFirstNameFilter"
Style="{StaticResource FilterPanelSearchTextBoxStyle}"
Text="{Binding Path=FirstNameFilter, UpdateSourceTrigger=PropertyChanged}"
/>
</StackPanel>
</DataTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“ctrlFilters”ContentControl 的 DataContext 中有当前视图模型,将其绑定到 Content 属性:
There is current view model in DataContext of the "ctrlFilters" ContentControl, bind it to Content property: