उपर्युक्त सुझावों (पृष्ठभूमि कार्यकर्ता, डिस्पैचर) के अतिरिक्त - हाँ, आप जो चाहते हैं उसे पाने के लिए ये सही तकनीक हैं, लेकिन मुझे आपके प्रश्न में आपके द्वारा अनुरोधित यूआई प्रभाव पर चर्चा करने दें। यदि आप एमवीवीएम पैटर्न का उपयोग कर रहे हैं, तो आप कुछ "मैं व्यस्त हूं" यूआई बना सकता हूं और यूआई को दिखाने और छिपाने के लिए दृश्य मॉडल में एक आईसबीसी संपत्ति से जुड़ सकता हूं। उदाहरण के लिए:
public class MyViewModel : INotifyPropertyChanged
{
// Bind to this property any UI you want to
// show/hide during long running updates
public bool IsBusy
{
get { return _isBusy; }
set
{
_isBusy = true;
OnPropertyChanged("IsBusy");
}
}
private void OnPropertyChanged(string prop)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(prop));
}
}
// Note: This is intended to be called on a background thread
private void DoLongRunningOperationOnABackgroundThread()
{
try
{
IsBusy = true;
// do your work
}
finally
{
IsBusy = false;
}
}
}
फिर यूआई प्रयोग में यह XAML (या इसी तरह)
<UserControl:MyControl x:Class="MyApp.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="boolToVis"/>
</UserControl.Resources>
<Grid>
<!-- your UI code goes here -->
<!-- Below this, at higher Z-Order place a control to gray out the screen when IsBusy = true -->
<Border Background="#55000000" BorderThickness="0" Visibility="{Binding IsBusy, Converter={StaticResource boolToVis}}">
<TextBlock Text="I AM BUSY!" Font-Size="32" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
</Border>
<Grid>
</UserControl>
शुद्ध प्रभाव है जब आप अपने viewmodel में DoLongRunningOperation समारोह कॉल करने के लिए एक पृष्ठभूमि के कार्यकर्ता या ThreadPool का उपयोग किया जाएगा, Xaml में परिभाषित सीमा ऑपरेशन शुरू होने/बंद होने के रूप में दिखाएगी/छुपाएगी। आपको यहां आने के लिए प्रेषक की आवश्यकता नहीं होगी क्योंकि WPF आपके लिए थ्रेड मार्शलिंग को संभालता है।
यूआई को मसाला करने के लिए नेट पर whirlygig एनिमेशन आदि के साथ व्यस्त नियंत्रण के कार्यान्वयन भी हैं।
सर्वश्रेष्ठ संबंध,
स्रोत
2012-01-03 11:51:08
बहुत बहुत धन्यवाद, यह बेहद सहायक था! –