大家好, 我需要使用busyindicator屏蔽屏幕。當我點擊視圖(Sample.xaml)時,事件被寫入(Sample.xaml.cs),導致執行寫入名爲(Sample.cs)的單獨類中的代碼。所以在單獨的類文件中我有busyindicator的實現。但它不起作用。BusyIndicator不工作在silverlight MVVM
Sample.xaml:
<UserControl x:Class="Pool.View.CadViewer"
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:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="400">
<Grid>
<toolkit:BusyIndicator IsBusy="{Binding IsBusy}">
<Grid x:Name="CadLayoutRoot" MouseLeftButtonUp="CadLayoutRoot_MouseLeftButtonUp" MouseRightButtonDown="CadLayoutRoot_MouseRightButtonDown" MouseRightButtonUp="CadLayoutRoot_MouseRightButtonUp" MouseLeftButtonDown="CadLayoutRoot_MouseLeftButtonDown" MouseMove="CadLayoutRoot_MouseMove" MouseWheel="CadLayoutRoot_MouseWheel" LostMouseCapture="CadLayoutRoot_LostMouseCapture" >
</Grid>
</toolkit:BusyIndicator>
</Grid>
</UserControl>
Sample.xaml.cs:
private void CadLayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
UpdateViewAndViewModel();
}
private void UpdateViewAndViewModel()
{
Sample bfmobj = new BFM(View.CadViewer.radius2, View.CadViewer.model.Blocks,
View.CadViewer.Step, View.CadViewer.StepType, View.CadViewer.StepPosition);
}
Sample.cs:
public class Sample: ViewModelBase
{
public BFM(bool radius, DxfBlockCollection block, string step, string steptype, string stepposition)
{
this.Radius = radius;
this.Block = block;
this.Step = step;
this.StepType = steptype;
this.StepPosition = stepposition;
GetBFMPart();
}
private bool _isBusy;
public bool IsBusy
{
get { return _isBusy; }
set
{
if (_isBusy != value)
{
_isBusy = value;
OnPropertyChanged("IsBusy");
}
}
}
public void GetBFMPart()
{
IsBusy = true;
//code sample
IsBusy = false;
}
}
在函數GetBFMPart我有代碼來檢索數據。所以我需要屏蔽屏幕直到要檢索的數據。怎麼做?請幫助我解決這個問題。
你在哪裏執行'GetBFMPart'方法? – Jehof
我已編輯代碼@Jehof。 –
是否將DataContext設置爲視圖Pool.View.CadViewer的正確值? – Jehof