[英]WPF: How do I bind a window's ShowInTaskbar property to code-behind value?
I am attempting to bind my window's "ShowInTaskbar" property to a definition in the code-behind, but it is not recognized.我试图将窗口的“ShowInTaskbar”属性绑定到代码隐藏中的定义,但无法识别。 I also cannot programmatically assign the value in code-behind.
我也无法以编程方式分配代码隐藏中的值。 I can only manipulate it by directly editing the xaml, which is not ideal in my situation.
我只能通过直接编辑 xaml 来操作它,这在我的情况下并不理想。
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFTest"
mc:Ignorable="d"
FontFamily="Segoe UI Light"
FontSize="14"
Title="WPF Test"
Name="Window"
Icon="/Resources/icon.ico"
Height="500"
Width="600"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
Loaded="Window_Loaded"
StateChanged="Window_StateChanged"
Closing="Window_Closing"
ShowInTaskbar="{Binding ShowInTaskbar}"
>
<Grid></Grid>
</Window>
The property I have in the code-behind:我在代码隐藏中的属性:
private bool _showInTaskbar
public bool ShowInTaskbar
{
get
{
return _showInTaskbar;
}
set
{
_showInTaskbar = value;
OnPropertyChanged("ShowInTaskbar");
}
}
I have also tried:我也试过:
Window.ShowInTaskbar = false;
Why is my binding not being recognized?为什么我的绑定不被识别? Or, how can I simply define it in code-behind?
或者,我如何简单地在代码隐藏中定义它?
Ugh.啊。 It was because I was using the same name as the window naturally inherits.
那是因为我使用的名称与窗口自然继承的名称相同。 Once I changed my property to "ShowIconInTaskbar" I bound it and it functions properly.
一旦我将我的属性更改为“ShowIconInTaskbar”,我就绑定了它并且它可以正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.