Pergunta

I'd like to know if it's possible to:

  • I have window (Window1) with listview. Double click on element (Element1) of this listview open little popup window (Window2).
  • I'd like to set Element1 and Window2 opacity to 1, but Window1 to 0.2

Window2 is open as topmost with ShowDialog().HasValue, like

    this.Opacity = 0.2;
    selected.opacity = 1;
    Window2.opacity = 1;
    if(Window2.ShowDialog().HasValue())
        this.Opacity = 1;

@EDIT: main window, called "Window1":

private void Border_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                if (popup != null)
                    popup.Close();
                popup = new PopupWindow(ListView.SelectedItem as SelectedItem, sender as Border, this);
                popup.Topmost = true;
                ((Border)sender).Opacity = 1;
                this.Opacity = 0.2;
                popup.Opacity = 1;
                if (popup.ShowDialog().HasValue)
                {
                    this.Opacity = 1;
                }
            }
        }
Foi útil?

Solução

Unfortunately, what you are trying to achieve cannot be directly accomplished with WPF because Opacity values are kind of inherited by child controls. From the UIElement.Opacity Property page on MSDN:

Opacity is applied from parent elements on down the element tree to child elements, but the visible effects of the nested opacity settings aren't indicated in the property value of individual child elements. For instance, if a list has a 50% (0.5) opacity and one of its list items has its own opacity set to 20% (0.2), the net visible opacity for that list item will be rendered as if it were 10% (0.1), but the property value of the list item Opacity property would still be 0.2 when queried.

However, it is possible to fake your desired look by making certain elements within the Window semi opaque, while still having Opacity="1.0" for child elements. So, try removing the Opacity setting from the Window and instead set the Background to a see through colour like this:

window.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

Or even simpler:

window.Background = Brushes.Transparent;

Using a combination of transparent colours and low Opacity values on certain UI elements should get you what you want eventually.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top