网格的动态内容 [英] Dynamic content of a Grid

查看:91
本文介绍了网格的动态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据模型具有枚举类型的属性。我想知道是否有办法根据枚举类型的值动态放置用户控件?

My data model has a property of the enumeration type. I wonder if there is way to place dynamically a user control based on the value of the enumeration type?

我目前正在朝以下方向进行调查:

I am currently investigating in the following direction:

<Grid Name ="AdjustmentsArea" DockPanel.Dock ="Right" MinWidth ="100" Visibility ="Collapsed" >
    <ContentControl DataContext ="{Binding AjustmentView}">
        <Style TargetType ="model:AjustmentViews">
            <Style.Triggers>
                <DataTrigger Binding ="{Binding}"  Value ="Settings">
                    /// is it possible in principle to point a user control using a Setter ??? 
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ContentControl>
</Grid>

可能也是我走错了路。但是我想知道(学习)是否有可能在用户控件中实现对动态内容的这一要求,而不是使用隐藏/显示已暴露元素方法。

May be also I am on a wrong path. But I would like to know (learn) if it is possible to implement this requirement for dynamic content in user control, but not using hide/show exised element approach.

您会建议吗?

推荐答案

您可以根据触发器绑定值设置不同的模板

you can set different template depending on trigger binding value

<ContentControl DataContext ="{Binding AjustmentView}">
    <ContentControl.Style>
        <Style TargetType ="ContentControl">
            <Style.Triggers>
                <DataTrigger Binding="{Binding}" Value ="Settings">
                   <Setter Property="Template">
                      <Setter.Value>
                          <ControlTemplate> <!--template with UserControl here--> </ControlTemplate>
                      </Setter.Value>
                   </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ContentControl.Style>
</ContentControl>

例如当方向更改(水平或垂直)时,WPF滑块使用此方法

e.g. WPF Slider uses this approach when Orientation changes (Horizontal or Vertical)

这篇关于网格的动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆