ImageOpacity binding issue

Jun 17, 2011 at 4:47 PM

The popmenuitem image properties (such as ImageOpacity) do not seem to reflecting changes when using {Binding}. Command binding on the same popupmenuitem appears ok. Any help for this?

Coordinator
Jun 17, 2011 at 11:46 PM
Edited Jun 17, 2011 at 11:48 PM

Hi,

Thanks for this report. Could you however send me a sample code illustrating the issues you've come across?

That would help me lots since my free time is quite limited lately.

Regards

Ziad

Jun 19, 2011 at 7:59 PM

Thanks Ziadj, I thank you for your contribution and your time.

I have a ‘banner’ user control, used in a ‘main page’ user control. I want a context menu in the banner. So I used SL4Popupmenu, and set the ‘command’ property on the relevant menuitem to a dependency property of type command in the banner code behind. That works ok.

I also added a dependency property in the code behind to try to set an image’s opacity on the menu item based on a bool. In xaml the opacity value comes from a value converter. In debug mode the value converter code runs and returns the correct value. But the menuitem’s image does not reflect the changed value. In fact the ‘IsBlueTheme’ property never gets called in code, suggesting a binding path or other binding issue, but since some binding works, I am not sure what.

Any suggestions would be gratefully received…

Code in my banner user control:

XAML

<Pop:PopupMenu RightClickElements="OptionsBorder" LeftClickElements="OptionsBorder" FocusOnShow="False" HoverElements="OptionsBorder"

DataContext="{Binding ElementName=ucBanner}" >

<ListBox>

<Pop:PopupMenuItem Header="Sign out" Click="Logout_Click" />

<Pop:PopupMenuItem Header="Show Dashboard" Command="{Binding DashboardCommand}" />

<Pop:PopupMenuItem Header="Blue Theme" Click="Blue_Click" Command="{Binding ChangeThemeCommand}" CommandParameter="BlueTheme"

ImageOpacity="{Binding IsBlueTheme, Converter={StaticResource BooleanToOpacityValueConverter}}"

ImageWidth="16" ImageSource="/CIMS;component/Assets/Images/bullet_black.png" >

</Pop:PopupMenuItem>

<Pop:PopupMenuItem Header="Grey/Green Theme" Click="GreyGreen_Click" Command="{Binding ChangeThemeCommand}" CommandParameter="GreyGreenTheme"

ImageOpacity="{Binding IsGreyGreenTheme, Converter={StaticResource BooleanToOpacityValueConverter}}"

ImageWidth="16" ImageSource="/CIMS;component/Assets/Images/bullet_black.png" >

</Pop:PopupMenuItem>

</ListBox>

</Pop:PopupMenu>

CS partial

public static readonly DependencyProperty IsBlueThemeProperty = DependencyProperty.Register("IsBlueTheme", typeof(bool), typeof(BannerControl), null);

public bool IsBlueTheme

{

get

{

return (bool)GetValue(IsBlueThemeProperty);

}

set

{

SetValue(IsBlueThemeProperty, value);

}

}

public static readonly DependencyProperty ChangeThemeProperty = DependencyProperty.RegisterAttached("ChangeThemeCommand", typeof(ICommand), typeof(BannerControl), null);

public ICommand ChangeThemeCommand

{

get

{

return (ICommand)GetValue(ChangeThemeProperty);

}

set

{

SetValue(ChangeThemeProperty, value);

}

}


From: ZiadJ [email removed]
Sent: 17 June 2011 23:47
To: kevincharlessmith@hotmail.com
Subject: Re: ImageOpacity binding issue [SL4PopupMenu:261791]

From: ZiadJ

Hi,

Thanks for reporting this issue.

Could you please send me a sample code illustrating the issues you've come across?

That would help me lots since my free time is quite limited lately.

Regards

Ziad

Jun 20, 2011 at 9:44 AM

Hmmm, if I have two PopUpMenuItems, then setting ImageSource on 1 item using a valueconverter works. But if both items have ImageSource being set via binding, neither works.

<Pop:PopupMenuItem Header="Blue Theme" Click="Blue_Click" Command="{Binding ChangeThemeCommand}" CommandParameter ="BlueTheme" ImageOpacity="{Binding IsBlueTheme, Converter={StaticResource BooleanToOpacityValueConverter }}" ImageWidth="16" ImageSource="{Binding IsBlueTheme, Converter={StaticResource BooleanToImageValueConverter},ConverterParameter ='bullet_black.png'}" ></Pop:PopupMenuItem

>

 

 

<Pop:PopupMenuItem Header="Grey/Green Theme" Click="GreyGreen_Click" Command="{Binding ChangeThemeCommand}" CommandParameter ="GreyGreenTheme" ImageOpacity="{Binding IsGreyGreenTheme, Converter={StaticResource BooleanToOpacityValueConverter }}" ImageWidth="16" ImageSource="{Binding IsGreyGreenTheme, Converter={StaticResource BooleanToImageValueConverter},ConverterParameter ='bullet_black.png'}" ></Pop:PopupMenuItem

>

 

 

Jun 20, 2011 at 11:02 AM

I think the issue must be with my user control inside another user control. If I add a control that changes the UI element that launches the pop-up, I can get binding to work.