Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't figure out why button is disabled after adding a command
    text
    copied!<p>Edit: Here is the xaml for the window containing the command bindings.</p> <pre><code>&lt;dx:DXWindow x:Class="Client.App.Support.AskAQuestionDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:libRes="clr-namespace:Shared.Lib.Resources;assembly=Shared.Lib" xmlns:support="clr-namespace:Client.App.Support" Title="{x:Static libRes:Strings.AskAQuestion}" Loaded="DXWindow_Loaded" Height="260" Width="600"&gt; &lt;Window.CommandBindings&gt; &lt;CommandBinding Command="support:AskAQuestionDialog.ListToSendCommand" Executed="MainWindowCommandBinding_Executed" CanExecute="CommandBinding_CanExecute"/&gt; &lt;/Window.CommandBindings&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Grid.Row="0" Orientation="Vertical"&gt; &lt;TextBlock Style="{StaticResource DatailsHeaderTextStyle}" Margin="4,4,4,4" Text="{x:Static libRes:Strings.Subject}"/&gt; &lt;TextBox Name="_subjectTextBox" AcceptsReturn="False" TextChanged="_subjectTextBox_TextChanged" Margin="2" MaxLines="1" TextWrapping="NoWrap"/&gt; &lt;TextBlock Style="{StaticResource DatailsHeaderTextStyle}" Margin="4,4,4,4" Text="{x:Static libRes:Strings.Description}"/&gt; &lt;TextBox VerticalAlignment="Stretch" Name="_descriptionTextBox" VerticalScrollBarVisibility="Auto" TextWrapping="WrapWithOverflow" AcceptsReturn="True" TextChanged="_descriptionTextBox_TextChanged"/&gt; &lt;/StackPanel&gt; &lt;StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right"&gt; &lt;StackPanel.Resources&gt; &lt;Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"&gt; &lt;Setter Property="Width" Value="80"/&gt; &lt;Setter Property="Margin" Value="2"/&gt; &lt;/Style&gt; &lt;/StackPanel.Resources&gt; &lt;Button Name="Attach" Content="Attach Screen Shots" Click="Attach_Click" Width="140" HorizontalAlignment="Right"/&gt; &lt;Button Content="{x:Static libRes:Strings.Submit}" Click="Submit_Click" Margin="10,0,0,0"/&gt; &lt;Button Content="{x:Static libRes:Strings.Close}" Click="Close_Click" Margin="10,0,0,0"/&gt; &lt;Grid&gt; &lt;ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled"&gt; &lt;ItemsControl Name="_itemsControl" ItemsSource="{Binding ''}"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;WrapPanel Orientation="Horizontal"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Image Name ="_thumbnailImage" HorizontalAlignment="Left" VerticalAlignment="Center" Source="{Binding ''}"/&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>And the relevant code behind:</p> <pre><code>private void MainWindowCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { if (e.Command == ListToSendCommand) { this._itemsControl.ItemsSource = (List&lt;BitmapSource&gt;)e.Parameter; } } </code></pre> <p>I've been learning about <code>RoutedCommands</code> in WPF and I ran into a problem after adding a command to a button. In my window, <code>SelectScreenShots</code>, I have a single <code>CommandBinding</code> that is handled in the code behind.</p> <p>I have another window, <code>AskAQuestionDialog</code>, with another command binding that is handled in its code behind.</p> <p>In <code>SelectScreenShots</code> I added the command that is handled in <code>AskAQuestion</code> to a button and now the button is constantly disabled. Before when I was just using a click event, it worked fine.</p> <p>Why is the button now disabled?</p> <p>Here is the xaml. The command I added is <code>ListToSendCommand</code> on the button <code>_OK_Button</code>.</p> <pre><code>&lt;dxc:DXWindow x:Class="Client.App.Support.SelectScreenShots" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/core" Focusable="False" IsTabStop="False" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:libRes="clr-namespace:Shared.Lib.Resources;assembly=Shared.Lib" xmlns:support="clr-namespace:Client.App.Support" Title="Select Images" Height="600" Width="800"&gt; &lt;Window.CommandBindings&gt; &lt;CommandBinding Command="support:SelectScreenShots.SelectImageCommand" Executed="MainWindowCommandBinding_Executed"/&gt; &lt;/Window.CommandBindings&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="367"/&gt; &lt;RowDefinition Height="167"/&gt; &lt;RowDefinition Height="33"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;ContentPresenter Grid.Row="0" Name="_contentPresenter" Content="{Binding ''}"/&gt; &lt;ContentPresenter Grid.Row="1" Name="_contentPresenter2" Content="{Binding ''}"/&gt; &lt;StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal"&gt; &lt;Button Name="_OK_Button" Content="OK" Margin="0,5,5,5" Width="75" Height="23" Command="{x:Static support:AskAQuestionDialog.ListToSendCommand}" CommandParameter="{Binding ''}" IsEnabled="True"/&gt; &lt;Button Name="_Cancel_Button" Content="Cancel" Click="_Cancel_Button_Click" Margin="0,5,5,5" Width="75" Height="23"/&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload