4

LayoutAwareページにポップアップコントロールがあります。

私が本当に欲しいのは、ポップアップが画面いっぱいに表示されることです。

解決策は、Window.Current.Bounds.Height / Widthを使用して、ポップアップコントロール内のグリッドにそれぞれのプロパティを設定することだと思います。

これらのプロパティを設定するためにコードビハインドファイルを使用したくありません。XAMLでWindow.Current.Bounds.Heightにバインドできるようにしたいと思います。

これはできますか?

ポップアップを画面全体に表示するためのより良い方法はありますか?

4

2 に答える 2

5

あなたは高さと幅のためのコンバーターを書くことによってそれをすることができます。

public class WidthConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        return Window.Current.Bounds.Width;
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}

public class HeightConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        return Window.Current.Bounds.Height;
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}

これをページリソースセクションに追加します-

    <common:WidthConverter x:Key="wc" />
    <common:HeightConverter x:Key="hc" />

ポップアップに使用してください-

        <Popup x:Name="myPopup"  >
            <Grid  Background="#FFE5E5E5" Height="{Binding Converter={StaticResource hc}}" Width="{Binding Converter={StaticResource wc}}" />
        </Popup>
于 2012-11-20T11:06:08.390 に答える
4

コンバーター(Typistを参照)を使用するか、静的クラスを使用できます。

App.xamlで:

<datamodel:Foo x:Name="FooClass" />
xmlns:datamodel="using:MyProject.Foo.DataModel"

そしてあなたのxamlで:

Source="{Binding Source={StaticResource FooClass}, Path=Width}"

ここで、Widthは、Window.Current.Bounds.Widthを返すクラス内のプロパティです。

サンプル :public double Width{get{return Window.Current.Bounds.Width;}}

よろしく。

于 2012-11-20T12:41:31.117 に答える