多数据触发器和 VisualState

发布于 2024-09-28 15:32:51 字数 1632 浏览 0 评论 0原文

我正在尝试创建一个菜单系统,在面板因视觉状态更改而关闭之后但在面板重新打开之前(想想滑入/滑出过滤器),它会更改面板的内容模板。我希望使用数据触发器的组合来实现这一点,但我没有喜悦:(为了简洁起见,省略了一些代码,但我的触发器设置如下所示:

<ContentControl x:Name="contentControl" Content="{Binding SelectedThing}"
                                DataContext="{Binding}" Width="200">
                    <ContentControl.ContentTemplate>
                        <DataTemplate>
                          <ContentControl Name="cc"
                                          Content="{Binding}" />
                            <DataTemplate.Triggers>

                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition Value="People"
                                                   Binding="{Binding Path=Name}">
                                        </Condition>

                                        <Condition Value="0"
                                                   Binding="{Binding ElementName=contentControl,Path=Width}">
                                        </Condition>
                                    </MultiDataTrigger.Conditions>
                                    <Setter TargetName="cc"
                                            Property="ContentTemplate"
                                            Value="{StaticResource PeopleTemplate}" />
                                </MultiDataTrigger>

......

当我省略绑定时,触发器会正确更改模板contentControl 宽度,但我无法确定原因(宽度通过视觉状态的变化进行动画处理)?

谢谢

I am trying to create a menu system which changes the content template for a panel AFTER the panel has been closed by a Visual State change but before the panel is re-opened (think of a slide in/out filter). I was hoping to achieve this using a combination of data triggers but am having no joy :( Some code has been ommited for brevity but my trigger setup looks as follows:

<ContentControl x:Name="contentControl" Content="{Binding SelectedThing}"
                                DataContext="{Binding}" Width="200">
                    <ContentControl.ContentTemplate>
                        <DataTemplate>
                          <ContentControl Name="cc"
                                          Content="{Binding}" />
                            <DataTemplate.Triggers>

                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition Value="People"
                                                   Binding="{Binding Path=Name}">
                                        </Condition>

                                        <Condition Value="0"
                                                   Binding="{Binding ElementName=contentControl,Path=Width}">
                                        </Condition>
                                    </MultiDataTrigger.Conditions>
                                    <Setter TargetName="cc"
                                            Property="ContentTemplate"
                                            Value="{StaticResource PeopleTemplate}" />
                                </MultiDataTrigger>

....

The trigger changes the template correctly when I omit the binding on contentControl width but I can't determine why (the width is animated via a change in visual state)?

Any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2024-10-05 15:32:51

尝试将 Path=Width 更改为 Path=ActualWidth。

我假设触发器没有触发,因为 Width 属性实际上并未报告它为 0。

您可以使用 Snoop 来确认此 http ://snoopwpf.codeplex.com/

Try changing Path=Width to Path=ActualWidth.

I assume the trigger is not firing because the Width property is not actually reporting that it is 0.

You can use Snoop to confirm this http://snoopwpf.codeplex.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文