おそらく、タイトルの言い回しが間違っています。
チャイルドウィンドウが開いているときに使用しようとしない限り、うまく機能する「グローバル」ビジーインジケーターがあります。
App.xaml.csで静的メソッドを使用して、「グローバル」ビジーインジケーターにアクセスします。
BusyIndicator b = (BusyIndicator)App.Current.RootVisual;
if (b != null)
{
b.BusyContent = busyText;
b.IsBusy = true;
}
ただし、ChildWindowが開いている場合、BusyIndicatorは常にその背後にあります。
設定できると思いましたb.Content = VisualTreeHelper.GetOpenPopups().First()
が、それもうまくいきませんでした。
開いているChildWindowsの上にBusyIndicatorを配置するためのヒントはありますか?
前もって感謝します。
更新(解決策)
デイブSは私を正しい軌道に乗せてくれました。思っていたよりも複雑でしたが、これが私の解決策です。
まず、ChildWindowの完全なスタイルを作成し、すべてのテンプレートスタイルをコピーする必要がありました(サイズ変更後の理由で一部を省略しました)。
<Style x:Key="MyChildWindowStyle" TargetType="gs:MyChildWindow">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="gs:MyChildWindow">
<toolkit:BusyIndicator IsBusy="{TemplateBinding IsBusy}" BusyContent="{TemplateBinding BusyContent}" BusyContentTemplate="{StaticResource MyBusyIndicatorDataTemplate}">
<Grid>
<ContentPresenter x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</toolkit:BusyIndicator>
</Style>
次に、基本クラスを作成しました。コンストラクターがスタイルを設定していることに注意してください。(抽象化しようとするとエラーが発生しました。)
public class MyChildWindow : ChildWindow
{
public static readonly DependencyProperty IsBusyProperty = DependencyProperty.Register("IsBusy", typeof(bool), typeof(MyChildWindow), null);
public static readonly DependencyProperty BusyContentProperty = DependencyProperty.Register("BusyContent", typeof(object), typeof(MyChildWindow), null);
public bool IsBusy
{
get { return (bool)GetValue(IsBusyProperty); }
set { SetValue(IsBusyProperty, value); }
}
public object BusyContent
{
get { return GetValue(BusyContentProperty); }
set { SetValue(BusyContentProperty, value); }
}
public MyChildWindow()
{
this.Style = Application.Current.Resources["MyChildWindowStyle"] as Style;
}
}
必ず新しいChildWindowを追加し、<controls:ChildWindowを<gs:MyChildWindowに変更してください(コードビハインドと同じ)。
最後に、静的SetBusyIndicatorメソッドを更新します。
public static void SetBusyIndicator(string busyText, Uri busyImage)
{
var op = VisualTreeHelper.GetOpenPopups().Where(o => o.Child is MyChildWindow);
if (op.Any())
{
var bidc = new MyBusyIndicatorDataContext(busyText, busyImage);
foreach (System.Windows.Controls.Primitives.Popup p in op)
{
var c = p.Child as MyChildWindow;
c.BusyContent = bidc;
c.IsBusy = true;
}
}
else
{
BusyIndicator b = Current.RootVisual as BusyIndicator;
if (b != null)
{
b.BusyContent = new MyBusyIndicatorDataContext(busyText, busyImage);
b.IsBusy = true;
}
}
}
これが最も効率的かどうかはわかりませんが、うまく機能しているようです。