why a Slider in menu can not Binding Background.Opacity of layoutRoot,but grdPopupMenu(a grid control)can

Jan 7, 2013 at 3:04 AM

hi,i have a issue,but my english is ugly.
why a Slider in menu can not Binding Background.Opacity of layoutRoot,but grdPopupMenu(a grid control)can
you know i want to change the Background.Opacity of layoutRoot
the main code as follow
xaml:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="PopupMenuApp.UserControl2"
d:DesignWidth="640" d:DesignHeight="480"
xmlns:my="clr-namespace:SL4PopupMenu;assembly=SL4PopupMenu"
>

<Grid x:Name="LayoutRoot" Background="#FFCB6969">
<Rectangle Fill="#FFF4F4F5" Height="98" Margin="146,108,182,0" Stroke="Black" VerticalAlignment="Top"/>
<my:PopupMenu x:Name="pmMain"
RightClickElements="LayoutRoot"
AccessShortcut="Ctrl+Alt+M"
AccessShortcutTargetElementName="LayoutRoot"
>

<!--The ItemsControl can also be placed inside a Grid or any other FrameworkElement within the menu-->
<!--In this case the PopupMenu will use the first ItemsControl(lstPopupMenu in our case) it finds in its content-->
<Grid x:Name="grdPopupMenu" Background="#FFB01C99" >
<!--See code behind where more items are added to this listbox -->
<ListBox x:Name="lstPopupMenu" Margin="20,0,0,0" >
<my:PopupMenuItem x:Name="pmiCut" Header="Cut" Tag="ClipboardMenuTag" ImageSource="../images/Cut.png" />
<my:PopupMenuItem x:Name="pmiCopy" Header="Copy" Tag="ClipboardMenuTag" ImageSource="../images/Copy.png" />
<!--This implementation provides control over the header content-->
<my:PopupMenuItem x:Name="pmiPaste" ImageSource="../images/Paste.png">
<TextBlock Text="Paste" Tag="ClipboardMenuTag"/>
</my:PopupMenuItem >
<my:PopupMenuSeparator Tag="ClipboardMenuTag"/>
<my:PopupMenuItem x:Name="pmiOrientableMenu" Header="Orientable Menu" CloseOnClick="False" ImageSource="../images/4_direction.png" ImageRightSource="../images/arrow.png" />
<my:PopupMenuSeparator/>
</ListBox>
</Grid>
</my:PopupMenu>
<Slider x:Name="stpTransparency" Height="35" VerticalAlignment="Center"
Value="{Binding Background.Opacity, ElementName=grdPopupMenu, Mode=TwoWay}" Maximum="1" HorizontalAlignment="Center" Width="200"/>

</Grid>
</UserControl>

csharp code behind:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace PopupMenuApp
{
public partial class UserControl2 : UserControl
{
public UserControl2()
{
// 为初始化变量所必需
InitializeComponent();


pmMain.AddItem(stpTransparency).CloseOnClick = false;

}
}
}

Jan 7, 2013 at 3:04 AM

thanks