0

ポップアップウィンドウが(クリック後に)表示された場合、メインウィンドウの明るさを下げる必要があります。誰かがそれを行う方法を知っているかもしれません。

例: ここに画像の説明を入力

編集:キャンバスを作成しましたが、使用方法がわかりません。輝度を下げる必要があり、ポップアップが表示されます。

コード:

private void sample_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            string path1 = System.AppDomain.CurrentDomain.BaseDirectory + "../../loader_bg.png";
            string path2 = System.AppDomain.CurrentDomain.BaseDirectory + "../../loader.gif";

            ImageBrush myBrush = new ImageBrush();
            Image image = new Image();
            image.Source = new BitmapImage(
                new Uri(path1));
            myBrush.ImageSource = image.Source;

            Image ima = new Image();
            MediaElement gif = new MediaElement();

            ima.Source = new BitmapImage(new Uri(path1));
            gif.Source=new Uri(path2);

            gif.Height = 72;
            gif.Width = 72;

            var pop = new Popup
            {
                IsOpen = true,
                StaysOpen = false,
                AllowsTransparency = true,
                VerticalOffset = 350,
                HorizontalOffset = 700,
                Height = 128,
                Width = 128,

            };
            Canvas c=new Canvas();
            c.Background=Brushes.Black;
            c.Opacity = 0.6;


            Grid p = new Grid();
            p.Background = myBrush; 

            //p.Children.Add(ima);
            //p.Children.Add(c);
            p.Children.Add(gif);
            pop.Child = p;


        }
    }

EDIT 2: 同じ質問がありますが、私のコードだけが変更されています。今、ポップアップ ウィンドウ用に新しい xaml.cs を作成し、同じ目的を達成しようとしましたが、同じ結果が得られませんでした (明るさの減少について話します)。その私の新しい xaml.cs :

namespace uploader
{
    /// <summary>
    /// Interaction logic for PopupPanel.xaml
    /// </summary>
    public partial class PopupPanel : UserControl
    {
        private Popup _currentPopup;
        public PopupPanel()
        {
            InitializeComponent();

            string path1 = System.AppDomain.CurrentDomain.BaseDirectory + "../../loader_bg.png";
            string path2 = System.AppDomain.CurrentDomain.BaseDirectory + "../../loader.gif";

            ImageBrush myBrush = new ImageBrush();
            Image image = new Image();
            image.Source = new BitmapImage(new Uri(path1));
            myBrush.ImageSource = image.Source;


            MediaElement gif = new MediaElement();

            gif.Source=new Uri(path2);

            gif.Height = 72;
            gif.Width = 72;

            _currentPopup = new Popup
            {

                StaysOpen = false,
                AllowsTransparency = true,
                VerticalOffset = 350,
                HorizontalOffset = 700,
                Height = 128,
                Width = 128,

            };
            Overlay.Visibility = Visibility.Visible;

            _currentPopup.Closed += PopupClosing;
            _currentPopup.IsOpen = true;

            Grid p = new Grid();
            p.Background = myBrush; 
            p.Children.Add(gif);

            _currentPopup.Child = p;

        }
        private void PopupClosing(object sender, EventArgs e)
        {
            _currentPopup.Closed -= PopupClosing;
            _currentPopup = null;

            Overlay.Visibility = Visibility.Collapsed;
        }
    } 
}

私の Mainwindow.xaml.cs:

namespace uploader
{

    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
        }
        private void sample_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            PopupPanel pop = new PopupPanel();
        }
...
4

2 に答える 2

1

すべての WPF アプリケーションで、黒の背景と不透明度を持つ Canvas を使用してこれを行います

例:

<Window>
    <Grid>
        <!--Main content-->
        <UserControl/>
        <Grid>
            <Canvas Background="Black" Opacity="0.6"/>
            <!--Overlay content-->
            <UserControl VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Grid>         
    </Grid>
</Window>
于 2015-08-03T12:02:38.800 に答える
0

現在のコードを使用して、Canvas オーバーレイの可視性を処理する必要があります。

以下に示すように、XAML 内で定義する方が簡単です。

<Window>
    <Grid>
        <!--Main content-->
        <UserControl/>
        <Grid>
            <Canvas x:Name="Overlay" 
                    Background="Black" 
                    Opacity="0.6"
                    Visibility="Collapsed"/>
            <!--Overlay content-->
            <UserControl VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Grid>         
    </Grid>
</Window>

次に、コード ビハインドで、ポップアップが開く前と閉じたときの可視性を設定できます。

Popup _currentPopup;

private void sample_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ...

    _currentPopup = new Popup
    {
        StaysOpen = false,
        AllowsTransparency = true,
        VerticalOffset = 350,
        HorizontalOffset = 700,
        Height = 128,
        Width = 128
    };

    Overlay.Visibility = Visibility.Visible;

    _currentPopup.Closed += PopupClosing;
    _currentPopup.IsOpen = true;

}

private void PopupClosing(object sender, EventArgs e)
{
    _currentPopup.Closed -= PopupClosing;
    _currentPopup = null;

    Overlay.Visibility = Visibility.Collapsed;
}

ポップアップへの参照を保持するためにローカル変数を使用していることに注意してください。これは、Closing イベントのサブスクライブを解除できるようにするためです (メモリ リークの防止に役立ちます)。

于 2015-08-03T12:44:45.460 に答える