Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从WPF中的类触发xaml代码?_Xaml - Fatal编程技术网

如何从WPF中的类触发xaml代码?

如何从WPF中的类触发xaml代码?,xaml,Xaml,它工作得很好: <Button Width="100" Height="30" Content="Click Me!"> <Button.ToolTip> <Border Margin="-4,0,-4,-3" Padding="10" Background="Silver"> <Border.BitmapEffect> <OuterGlowBit

它工作得很好:

  <Button Width="100" Height="30" Content="Click Me!">
      <Button.ToolTip>
          <Border Margin="-4,0,-4,-3" Padding="10" Background="Silver">
             <Border.BitmapEffect>
                 <OuterGlowBitmapEffect></OuterGlowBitmapEffect>
             </Border.BitmapEffect>
                <Label>Nice tooltip</Label>
             </Border>
          </Button.ToolTip>
  </Button>

很好的工具提示
但是,我希望在有条件时撤销代码。例如:

 if(str=="aaa")
    MessageBox.Show("All will be o'kay");
 else 
  {
      //I would like this code to revoke
      /*  <Border.BitmapEffect>
              <OuterGlowBitmapEffect></OuterGlowBitmapEffect>
          </Border.BitmapEffect>
       */
   }
if(str==“aaa”)
MessageBox.Show(“一切都将是奥凯”);
其他的
{
//我想撤销这个代码
/*  
*/
}

如何操作?

只需创建一个引发通知的属性。您可以实现INotifyPropertyChanged接口。更改代码中属性的值并用xaml绑定它