【发布时间】:2015-02-25 17:34:22
【问题描述】:
我有这个用户控件:我将此用户控件添加到我的 Winforms 应用程序(简单的 BusyIndicator):
<UserControl x:Class="MyApp.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<xctk:BusyIndicator x:Name="busyIndicator" IsBusy="{Binding IsBusy}" />
</Grid>
</UserControl>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public void SetIndicator(bool isBusy)
{
busyIndicator.IsBusy = isBusy;
}
}
现在我尝试从我的主要表单开始我的BusyIndocator:
UserControl1 uc = new UserControl1();
uc.SetIndicator(true);
另外,如果我将 IsBusy="{Binding IsBusy}" 更改为 IsBusy="true,我可以看到我的 BusyIndicator,但我无法停止它。
但是什么也没发生,我做错了什么?
【问题讨论】:
-
1)这是winforms还是wpf?应该是后者,但是为什么winforms标签呢? 2)你在datacontext中绑定到
IsBusy到IsBusy,那你为什么要在SetIndicator方法中手动设置IsBusy属性呢? 3)你在哪里设置数据上下文? -
1) 这是winforms 2) 我设置了busyIndicator.IsBusy = isBusy;在 SetIndicator 函数 3) 你是什么意思 datacontext ?
-
winforms从什么时候开始使用xaml?
-
我在询问后添加了 wpf usercontrol 并告诉我它可能
-
1)这不可能是winforms,你确定吗?你在使用 winforms/wpf 互操作吗? 2)为什么在使用 DataBinding 时设置
busyIndicator.IsBusy? 3)我认为你对你使用的技术有错误的理解。请先学习wpf here
标签: c# wpf winforms busyindicator