1

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;
                }
            }
        }
user1617141
  • 115
  • 1
  • 11
  • Yes. Window1 opacity is 0.2 and only popup (Window2) is 1. I need the element to set also to 1 ;) – user1617141 Mar 19 '14 at 15:11
  • It seems like you have a click method where you open the popup when u clicked the element. Isn't there a handle from the element as parameter? – Mighty Badaboom Mar 19 '14 at 15:16
  • You mean pass Element1 to window and set opacity to 1 in new open window? Also doesn't work – user1617141 Mar 19 '14 at 15:21
  • Not exactly what I'm talking about. What I wanted to say: you must have an event like click event where you open the second window (as shown in your example). Do you have any reference from your elemtn in this method? Maybe it would be easier if you would post a bit more code. – Mighty Badaboom Mar 19 '14 at 15:25
  • Sure, I'll edit first post and add code. – user1617141 Mar 19 '14 at 15:35
  • Have a look at this article: [http://stackoverflow.com/questions/982103/opaque-element-in-a-transparent-in-wpf][1] [1]: http://stackoverflow.com/questions/982103/opaque-element-in-a-transparent-in-wpf – aDoubleSo Mar 19 '14 at 15:59
  • Well, I don't really understand how changing background of my grid would help me. Also - in grid i have a lot of other controls for which I'd like to change opacity. – user1617141 Mar 19 '14 at 16:29

1 Answers1

1

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.

Sheridan
  • 68,826
  • 24
  • 143
  • 183