WPF自定义控件,基于列模板切换

时间:2014-02-24 08:35:53

标签: wpf wpf-controls

我正在构建一个基于bool属性的自定义用户控件应该显示基于此属性的模板或其他...我不知道如何切换....

这是一些代码

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();


        rapportoSeachViewModel = DataContext as RapportoSearchViewModel;

        tbRapporto = base.Template.FindName("PART_SearchTextBox", this) as TextBox;

        if (tbRapporto != null)
        {
            tbRapporto.KeyDown += tbRapporto_KeyDown;
        }

        searchButton = base.Template.FindName("PART_SearchButton", this) as Button;

        if (searchButton != null)
        {
            searchButton.Click += searchButton_Click;
        }
    }

,当属性设置为true时,这是我的模板

                                                                                                                                                                                                                                                                                                                                                                                                             

如何在资源字典中定义另一个模板以及如何切换它? 提前致谢

1 个答案:

答案 0 :(得分:0)

您可以使用DataTemplateSelector来满足您的要求。

link:http://msdn.microsoft.com/en-us/library/system.windows.controls.datatemplateselector(v=vs.110).aspx