【发布时间】:2017-08-31 21:52:05
【问题描述】:
我有 2 个用户控件,UC1 和 UC2: UC1:有 3 个切换按钮,Button1、Button2、Button3 UC2:拥有带有 UI 元素的画布。等:椭圆1
我想在 Button1.ischecked == true 时隐藏 ellipse1
我暴露了togglebutton的checked状态,但我一直读的是false。
UC1:
public ButtonLayout()
{
InitializeComponent();
}
public bool IsToggleChecked
{
get { return (bool)Button1.IsChecked; }
}
UC2:
ButtonLayout buttons = new ButtonLayout();
if (buttons.IsToggleChecked == true)
{
elip1.Visibility = Visibility.Hidden;
}
请告诉我哪里出错了
【问题讨论】:
-
按原样,您的示例将为 false,因为 IsChecked 的默认值为 false,并且由于您似乎在构建 ButtonLayout 类后立即读取了该值,因此没有时间让它成为其他任何东西.我认为您的代码比这更复杂,所以也许您应该编辑问题以更好地反映您的问题。