How to dynamically change a WPF control's template using a checkbox?

后端 未结 2 763
有刺的猬
有刺的猬 2021-02-06 09:12

I have an error dialog (shown simplified below).

I display the Report object in a ContentControl to which I have defined a Template sim

2条回答
  •  隐瞒了意图╮
    2021-02-06 09:22

    This Solution is for those who are searching for Template swap. It is simple hope it helps you. Please point out any mistakes.

    Just use this code for changing the Template on checkBox Checked Event.

     private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
            DataTemplate Temp;
            Temp = (DataTemplate)this.FindResource("TemplateYouHaveCreated");
            listView1.ItemTemplate = Temp;
        }
    

    refer this link for more information

    http://developingfor.net/2009/01/09/dynamically-switch-wpf-datatemplate/

提交回复
热议问题