Click here to Skip to main content
15,887,214 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: SQLite Manager Pin
Richard MacCutchan22-Jul-15 22:18
mveRichard MacCutchan22-Jul-15 22:18 
AnswerRe: SQLite Manager Pin
Pete O'Hanlon22-Jul-15 22:49
mvePete O'Hanlon22-Jul-15 22:49 
GeneralRe: SQLite Manager Pin
Kevin Marois23-Jul-15 3:50
professionalKevin Marois23-Jul-15 3:50 
QuestionDataBinding to an Icon Pin
Member 1027274820-Jul-15 8:23
Member 1027274820-Jul-15 8:23 
AnswerRe: DataBinding to an Icon Pin
Herman<T>.Instance23-Jul-15 11:31
Herman<T>.Instance23-Jul-15 11:31 
GeneralRe: DataBinding to an Icon Pin
Member 1027274824-Jul-15 1:36
Member 1027274824-Jul-15 1:36 
QuestionWPF Expander - Change Image Pin
Kevin Marois15-Jul-15 6:29
professionalKevin Marois15-Jul-15 6:29 
QuestionCustom Drop Down Menu Button Pin
Kevin Marois7-Jul-15 8:05
professionalKevin Marois7-Jul-15 8:05 
I'm trying to create a Drop Down Button UC. So far it's all going well except that the Content menu has no SelectedItem. So I tried this:

XAML
<Grid x:Name="layoutRoot">

<pre>
<Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Button Grid.Row="0" 
        Click="Button_Click">

    <StackPanel Orientation="Horizontal">
        <Image Source="sort_16.png"
                VerticalAlignment="Center"
                Height="16"
                Width="16"/>
        <Image Source="downarrow.png"
                VerticalAlignment="Center"
                Height="3"
                Width="5"/>

    </StackPanel>

    <Button.ContextMenu>
        <ContextMenu/>
    </Button.ContextMenu>

    <Button.Resources>

        <ContextMenu x:Key="menu" ItemsSource="{Binding MenuItems}">

            <ContextMenu.ItemTemplate> 
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">

                        <TextBlock  Text="{Binding Text}"/>
                        <MenuItem  Command="{Binding MenuItemSelectedCommand, Mode=TwoWay}"
                                    CommandParameter="{Binding}"/>

                    </StackPanel>
                </DataTemplate>
            </ContextMenu.ItemTemplate>

        </ContextMenu>

    </Button.Resources>

</Button>




Code behind
public partial class DFTDropDownButton : UserControl
{
    #region Commands
    private ICommand _MenuItemSelectedCommand;
    public ICommand MenuItemSelectedCommand
    {
        get
        {
            if (_MenuItemSelectedCommand == null)
                _MenuItemSelectedCommand = new RelayCommand<DropDownButtonMenuItem>(p => menuItemSelectedExecuted(p), p => menuItemSelectedCanExecute());
            return _MenuItemSelectedCommand;
        }
    }
    #endregion

<pre>
#region MenuItems DP
public List<DropDownButtonMenuItem> MenuItems
{
    get { return (List<DropDownButtonMenuItem>)GetValue(MenuItemsProperty); }
    set { SetValue(MenuItemsProperty, value); }
}

public static readonly DependencyProperty MenuItemsProperty =
DependencyProperty.Register("MenuItems", typeof(List<dropdownbuttonmenuitem>), typeof(DFTDropDownButton), new UIPropertyMetadata(null));
#endregion

#region CTOR
public DFTDropDownButton()
{
InitializeComponent();

this.layoutRoot.DataContext = this;
}
#endregion

#region Private Methods
private bool menuItemSelectedCanExecute()
{
return true;
}

private void menuItemSelectedExecuted(DropDownButtonMenuItem item)
{
}
#endregion

#region Event Handlers
private void Button_Click(object sender, RoutedEventArgs e)
{
Button b = sender as Button;
b.ContextMenu.ItemsSource = MenuItems;
b.ContextMenu.IsOpen = true;
}
#endregion
}


Problem
The Command never fires.

Anyone see what's wrong here?

Thanks
If it's not broken, fix it until it is

AnswerRe: Custom Drop Down Menu Button Pin
Richard Deeming7-Jul-15 11:36
mveRichard Deeming7-Jul-15 11:36 
GeneralRe: Custom Drop Down Menu Button Pin
Kevin Marois7-Jul-15 11:42
professionalKevin Marois7-Jul-15 11:42 
QuestionApply Styles To Custom Control Pin
Kevin Marois7-Jul-15 5:36
professionalKevin Marois7-Jul-15 5:36 
AnswerRe: Apply Styles To Custom Control Pin
Richard Deeming7-Jul-15 6:57
mveRichard Deeming7-Jul-15 6:57 
GeneralRe: Apply Styles To Custom Control Pin
Kevin Marois7-Jul-15 7:03
professionalKevin Marois7-Jul-15 7:03 
GeneralRe: Apply Styles To Custom Control Pin
Richard Deeming7-Jul-15 7:07
mveRichard Deeming7-Jul-15 7:07 
GeneralRe: Apply Styles To Custom Control Pin
Kevin Marois7-Jul-15 7:10
professionalKevin Marois7-Jul-15 7:10 
GeneralRe: Apply Styles To Custom Control Pin
Richard Deeming7-Jul-15 7:13
mveRichard Deeming7-Jul-15 7:13 
GeneralRe: Apply Styles To Custom Control Pin
Kevin Marois7-Jul-15 7:19
professionalKevin Marois7-Jul-15 7:19 
GeneralRe: Apply Styles To Custom Control Pin
Richard Deeming7-Jul-15 7:41
mveRichard Deeming7-Jul-15 7:41 
GeneralRe: Apply Styles To Custom Control Pin
Kevin Marois7-Jul-15 7:55
professionalKevin Marois7-Jul-15 7:55 
GeneralRe: Apply Styles To Custom Control Pin
Richard Deeming7-Jul-15 8:17
mveRichard Deeming7-Jul-15 8:17 
GeneralRe: Apply Styles To Custom Control Pin
Kevin Marois7-Jul-15 8:18
professionalKevin Marois7-Jul-15 8:18 
Questioncheck out of canvas Pin
ngthtra29-Jun-15 21:36
ngthtra29-Jun-15 21:36 
QuestionProblem in Show/Hide Control in a WPF User Control Pin
Ashfaque Hussain29-Jun-15 20:50
Ashfaque Hussain29-Jun-15 20:50 
AnswerRe: Problem in Show/Hide Control in a WPF User Control Pin
Richard Deeming30-Jun-15 1:10
mveRichard Deeming30-Jun-15 1:10 
GeneralRe: Problem in Show/Hide Control in a WPF User Control Pin
Ashfaque Hussain1-Jul-15 18:54
Ashfaque Hussain1-Jul-15 18:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.