This project has moved and is read-only. For the latest updates, please go here.

Elements Property in BookLibrary

Sep 16, 2014 at 12:32 AM
Edited Sep 16, 2014 at 12:37 AM

I am studying WAF and WPF (I am quite newbie).

I have analyzed heaps of time to figure out how the elements property are set in BookLibrary sample but I can't figure out.


When I look at the Remove button code at ToobarTray in BookListView.xaml
<Button Command="{Binding RemoveCommand}">
    <AccessText Text="{x:Static p:Resources.RemoveMenu}"/>
There is no property to disable this button.
Where is the property?
Also I cannot find the code to enable this button when user select a row in datagrid.
How this enable/disable works?

Same as Toolbar tray buttons in ShellWindow.
<Button Command="ApplicationCommands.Undo" Content="{StaticResource UndoImage}" ToolTip="{x:Static p:Resources.Undo}"/>
                <Button Command="ApplicationCommands.Redo" Content="{StaticResource RedoImage}" ToolTip="{x:Static p:Resources.Redo}"/>
                <Button Command="ApplicationCommands.Cut" Content="{StaticResource CutImage}" ToolTip="{x:Static p:Resources.Cut}"/>
                <Button Command="ApplicationCommands.Copy" Content="{StaticResource CopyImage}" ToolTip="{x:Static p:Resources.Copy}"/>
                <Button Command="ApplicationCommands.Paste" Content="{StaticResource PasteImage}" ToolTip="{x:Static p:Resources.Paste}"/>
Above buttons definitely has opacity property,
however there is no opacity in code level.
Also user change the data in the datagrid, those button's opacity change to 100%.
How this things works?

Could you explain how those things work?
Sep 19, 2014 at 7:03 PM
Enabling and Disabling of the ToolBar button is done by the Command.
public BookController(...)
    this.removeCommand = new DelegateCommand(RemoveBook, CanRemoveBook);

private bool CanRemoveBook() 
    return bookListViewModel.SelectedBook != null && bookListViewModel.IsValid && bookViewModel.IsValid; 
The button's opacity is defined in a Style. See ControlResources.xaml:
<Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="{x:Type Button}">
        <DataTrigger Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="False">
            <Setter Property="Opacity" Value="0.35"/>