Wpf Xaml禁用控件,直到执行其代码隐藏
我制作了一个自定义按钮,如下所示Wpf Xaml禁用控件,直到执行其代码隐藏,wpf,xaml,windows-runtime,winrt-xaml,Wpf,Xaml,Windows Runtime,Winrt Xaml,我制作了一个自定义按钮,如下所示 <Border x:Name="myBtn" Grid.Column="0" Width="320" Height="100" Margin="10" HorizontalAlignment="Right" Style="{StaticResource myBtnStyle}" Tapped="myBtn_Tapped"> <Grid> <TextBlock x:Uid="TBmyBtn" Margin="1
<Border x:Name="myBtn" Grid.Column="0" Width="320" Height="100" Margin="10" HorizontalAlignment="Right" Style="{StaticResource myBtnStyle}" Tapped="myBtn_Tapped">
<Grid>
<TextBlock x:Uid="TBmyBtn" Margin="100,20,20,20" Text="Update" Style="{StaticResource myTBStyle}"/>
</Grid>
</Border>
private async void myBtn_Tapped(object sender, TappedRoutedEventArgs e)
{
//Many Network Calls
//Updating Local DB
//Updating ViewModels
// Blah Blah Blah...
}
如果我点击我的自定义按钮(myBtn),它后面的代码就会开始执行,而且因为有很多网络调用,所以完成myBtn_Tapped函数需要一些时间
现在我的要求是,我应该禁用myBtn-tap,直到myBtn\u-tap完成它的执行
我试过的是
private async void myBtn_Tapped(object sender, TappedRoutedEventArgs e)
{
myBtn.IsTapEnabled=False;
//Many Network Calls
//Updating Local DB
//Updating ViewModels
// Blah Blah Blah...
myBtn.IsTapEnabled=True;
}
但我注意到,即使在myBtn.IsTapEnabled=False之后代码>,如果我点击一次myBtn,并且当myBtn_点击函数正在执行时,如果我再次点击myBtn,点击事件将被注册,并且函数在完成其执行后再次开始执行
如何停止myBtn的tap事件注册,直到其代码隐藏在事务中???不要在代码隐藏中实现应用程序逻辑。这违反了MVVM的理念。你应该实施你的计划
//许多网络电话
//更新本地数据库
//更新视图模型
//废话废话
在视图模型中,例如,提供绑定到按钮的命令
属性的ICommand
。该ICommand
还应实现CanExecute()
方法,该方法将您的按钮设置为启用或禁用状态。
然后你可以为你的按钮定义一个样式
,让它看起来像你想要的那样
因此,最终你的观点是这样的:
<Button Command="{Binding UpdateCommand}"/>
不要在代码隐藏中实现应用程序逻辑。这违反了MVVM的理念。你应该实施你的计划
//许多网络电话
//更新本地数据库
//更新视图模型
//废话废话
在视图模型中,例如,提供绑定到按钮的命令
属性的ICommand
。该ICommand
还应实现CanExecute()
方法,该方法将您的按钮设置为启用或禁用状态。
然后你可以为你的按钮定义一个样式
,让它看起来像你想要的那样
因此,最终你的观点是这样的:
<Button Command="{Binding UpdateCommand}"/>
不要在代码隐藏中实现应用程序逻辑。这违反了MVVM的理念。你应该实施你的计划
//许多网络电话
//更新本地数据库
//更新视图模型
//废话废话
在视图模型中,例如,提供绑定到按钮的命令
属性的ICommand
。该ICommand
还应实现CanExecute()
方法,该方法将您的按钮设置为启用或禁用状态。
然后你可以为你的按钮定义一个样式
,让它看起来像你想要的那样
因此,最终你的观点是这样的:
<Button Command="{Binding UpdateCommand}"/>
不要在代码隐藏中实现应用程序逻辑。这违反了MVVM的理念。你应该实施你的计划
//许多网络电话
//更新本地数据库
//更新视图模型
//废话废话
在视图模型中,例如,提供绑定到按钮的命令
属性的ICommand
。该ICommand
还应实现CanExecute()
方法,该方法将您的按钮设置为启用或禁用状态。
然后你可以为你的按钮定义一个样式
,让它看起来像你想要的那样
因此,最终你的观点是这样的:
<Button Command="{Binding UpdateCommand}"/>
不确定“禁用”到底是什么意思,但IshitteVisible
可能会给你带来最好的回报
async ClickHandler(sender, events)
{
Control.IsHitTestVisible = false;
await GetDataAsync();
Control.IsHitTestVisible = true;
}
//祝你好运 不确定“禁用”到底是什么意思,但IshitteVisible
可能会给你带来最好的回报
async ClickHandler(sender, events)
{
Control.IsHitTestVisible = false;
await GetDataAsync();
Control.IsHitTestVisible = true;
}
//祝你好运 不确定“禁用”到底是什么意思,但IshitteVisible
可能会给你带来最好的回报
async ClickHandler(sender, events)
{
Control.IsHitTestVisible = false;
await GetDataAsync();
Control.IsHitTestVisible = true;
}
//祝你好运 不确定“禁用”到底是什么意思,但IshitteVisible
可能会给你带来最好的回报
async ClickHandler(sender, events)
{
Control.IsHitTestVisible = false;
await GetDataAsync();
Control.IsHitTestVisible = true;
}
//祝你好运 我就是这样处理这种情况的。
我在这个特定的页面类中声明了一个标志&当方法启动时将其值设置为true
,当我的工作完成时,将其设置为false
public class myControl : UserControl
{
public bool IsWorking { get; set; }
private async void myBtn_Tapped(object sender, TappedRoutedEventArgs e)
{
if (IsWorking) //These 2 statements did the magic.!!
return;
IsWorking= true;
//Many Network Calls
//Updating Local DB
//Updating ViewModels
// Blah Blah Blah...
IsWorking= false;
}
}
我就是这样处理这种情况的。
我在这个特定的页面类中声明了一个标志&当方法启动时将其值设置为true
,当我的工作完成时,将其设置为false
public class myControl : UserControl
{
public bool IsWorking { get; set; }
private async void myBtn_Tapped(object sender, TappedRoutedEventArgs e)
{
if (IsWorking) //These 2 statements did the magic.!!
return;
IsWorking= true;
//Many Network Calls
//Updating Local DB
//Updating ViewModels
// Blah Blah Blah...
IsWorking= false;
}
}
我就是这样处理这种情况的。
我在这个特定的页面类中声明了一个标志&当方法启动时将其值设置为true
,当我的工作完成时,将其设置为false
public class myControl : UserControl
{
public bool IsWorking { get; set; }
private async void myBtn_Tapped(object sender, TappedRoutedEventArgs e)
{
if (IsWorking) //These 2 statements did the magic.!!
return;
IsWorking= true;
//Many Network Calls
//Updating Local DB
//Updating ViewModels
// Blah Blah Blah...
IsWorking= false;
}
}
我就是这样处理这种情况的。
我在这个特定的页面类中声明了一个标志&当方法启动时将其值设置为true
,当我的工作完成时,将其设置为false
public class myControl : UserControl
{
public bool IsWorking { get; set; }
private async void myBtn_Tapped(object sender, TappedRoutedEventArgs e)
{
if (IsWorking) //These 2 statements did the magic.!!
return;
IsWorking= true;
//Many Network Calls
//Updating Local DB
//Updating ViewModels
// Blah Blah Blah...
IsWorking= false;
}
}
你试试myBtn.IsEnabled=false怎么样?你试试myBtn.IsEnabled=false怎么样?你试试myBtn.IsEnabled=false怎么样?你试试myBtn.IsEnabled=false怎么样?先生,谢谢你的回答。但我并没有这样做。请检查我的答案,如果我错了就纠正我。谢谢先生的回答。但我并没有这样做。请检查我的答案,如果我错了就纠正我。谢谢先生的回答。但我并没有这样做。请检查我的答案,如果我错了就纠正我。谢谢先生的回答。但我并没有这样做。检查我的答案,如果我错了就纠正我。