I was trying to disable/Gray out the combo box once I select any other item like Radio Button Item. I have created the WPF form using Visual Studio & used the same xaml form in PowerShell. So, in the backend are the PowerShell functions which executes based on the selection. One such requirement is to get data when I select a Radio Button against a Combo Box. Item selected in the combo box should match with other combo box item otherwise my function wont work. The problem, which I'm facing is I'm not able Disable/Gray out it, even I tried by setting the item isenable=$false in PowerShell. If I set the same in XAML , it works but it doesn't fulfill the requirement otherwise I wont be able to select the items at all. Here is the code
<RadioButton Name="Radio_VM" Content="ASR Status" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="30,382,0,0" RenderTransformOrigin="0.133,0.393"/>
<ComboBox Name="Client" HorizontalAlignment="Left" Margin="15,230,0,0" VerticalAlignment="Top" Width="120" IsDropDownOpen="False" SelectedIndex="2" >
<ComboBoxItem Content="ABC"/>
<ComboBoxItem Content="DEF"/>
</ComboBox>
As soon as I select Radiobutton, it should Gray Out Combo Box.
You could use a Style with a DataTrigger that binds to the IsChecked property of the RadioButton:
<ComboBox Name="Client" HorizontalAlignment="Left" Margin="15,230,0,0" VerticalAlignment="Top" Width="120" IsDropDownOpen="False" SelectedIndex="2">
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=Radio_VM}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBoxItem Content="ABC"/>
<ComboBoxItem Content="DEF"/>
</ComboBox>
Related
Tooltip is not visible on disabled checkbox even after setting ToolTipService.ShowOnDisabled="True".
<CheckBox Grid.Column="0" HorizontalAlignment="Center" Visibility="{Binding Converter={StaticResource TaskCompletionVisbilityConverter},ConverterParameter='chkbox'}"
Height="16" Width="16" Foreground="{Binding Converter={StaticResource TaskColorConverter}}"
ToolTipService.ShowOnDisabled="True" ToolTipService.IsEnabled="True"
ToolTip="Check To complete Task"
IsEnabled="{Binding State, Converter={StaticResource EnableDisableConverter},
ConverterParameter='checkbox',Mode=TwoWay}" Margin="37,5,0,0">
Your code works for me. ToolTipService.ShowOnDisabled="True" should be what you need.
Please check that you haven't set IsHitTestVisible to false in any Style/ControlTemplate associated with the checkbox.
Setting IsHitTestVisible to false means that it will ignore any mouse events associated with the control and so you won't get the tooltip.
ToolTipService.ShowOnDisabled="True" was not working for me. Below works :
<DataGridCheckBoxColumn.CellStyle>
<Style>
<Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
</Style>
</DataGridCheckBoxColumn.CellStyle>
I have a WPF ListView/GridViwe in a MVVM application. GridView is bound to a List in the ViewModel.
The requirement is that the users should be able to select multiple rows of the gridview, right-click on it and see a context menu "Group These Together". Once selected, all these items should be collapsed into one group with a expander or + sign added at the beginning.
Can somebody please help me in getting this working?
I was working on similar problem, but I had to group items by their let's say name. What I've done was create DataTrigger or MultiDataTrigger depending on your data requirements and then when conditions are true i.e. item selected change the container for GroupItem. What I mean is when you create your list view, you have to create it with grouped view, which btw is not grouped as you can declare it without expander and just use the StackPanel. After that you need 3 lines of Code to set the grouping. Here is an example for you:
MAIN.xaml
<ListView
ScrollViewer.CanContentScroll="False"
x:Name="lsvProducts"
ItemsSource="{Binding Products, NotifyOnSourceUpdated=True}"
MouseDown="lsvProducts_MouseDown">
<ListView.View>
<GridView>
<GridViewColumn Width="Auto" Header="Code" DisplayMemberBinding="{Binding ID}"/>
<GridViewColumn Width="Auto" Header="Description" DisplayMemberBinding="{Binding Desc}"></GridViewColumn>
<GridViewColumn Width="Auto" Header="Qty" DisplayMemberBinding="{Binding Qty}"></GridViewColumn>
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupedView}"/>
</ListView.GroupStyle>
</ListView>
As you can see I have declared an empty container for the grouped style, reson why is because you can't assign it without previous declaration. After this declaration you need this in your generic.xaml
<Style x:Key="GroupedView" TargetType="{x:Type GroupItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=chbx, Path=IsChecked}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="False">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding ItemCount}" FontSize="16" Foreground="DimGray" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" item(s)" FontSize="16" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
After you declared your style for the true value you need to declare one for without expander
<!--This goes in the same style as the prevoius sample code -->
<DataTrigger Binding="{Binding ElementName=chbx, Path=IsChecked}" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<ItemsPresenter />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
Next step is to define the grouping:
//lsvProducts is our ListView
view = (CollectionView) CollectionViewSource.GetDefaultView(lsvProducts.ItemsSource);
//in the creation parameter you should put field that you want to group by :-)
PropertyGroupDescription grouping = new PropertyGroupDescription("FieldToGroupBy");
view.GroupDescriptions.Add(grouping);
Which should apper in your ViewModel.
Good luck!
Let us know if you need any more help, I'll try my best with my English ;-)
EDIT
I forgot to mention when you assign the grouping you need to check the number of groups already in the collection and only apply it when there is non or 0, otherwise you'll apply the grouping multiple times and the expander will be repeeated in the result window as many times as you added the grouping :-)
What in my mind to select multiple row Ctrl+click
It will select multiple row and on right click open a context menu after setting its Isopen to true
You should also bind selected item to list and Use this item to make an expander
I have a DataGrid with two columns:
DataGridComboBoxColumn
DataGridTextColumn.
I have set up data validation so that if one has a value, the other will be in error until it also has a value. The validation is silly, but it provides some simple criteria with which to do validation so I can illustrate this issue.
When I type something into the text cell, press tab, then click back on the first cell, the first cell shows that it is in an error state (which is correct). The problem is that when I select something from the combo box dropdown and navigate away from that cell (either by pressing tab or by clicking in another cell), the value I selected for the combo box disappears. I have the binding set to update my source whenever the property changes, so it gets set to the value I select as soon as I select it. But, when I navigate away from the cell, the property gets set to null. I do not see this behavior if the cell is not in an error state.
Can anyone help please? Here is the XAML for my DataGrid:
<DataGrid Grid.Row="2"
Name="GrdData"
ItemsSource="{Binding Path=Dvm.Data}"
SelectedItem="{Binding Path=Dvm.SelectedData, Mode=TwoWay}"
CanUserAddRows="True"
CanUserDeleteRows="False"
AutoGenerateColumns="False"
Margin="5"
SelectionMode="Single"
IsEnabled="{Binding Path=IsGridEnabled}">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Column 1"
SelectedItemBinding="{Binding Path=Col1, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
Width="*"
DisplayMemberPath="Description">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding Path=DropDownValues, Mode=OneWay}" />
<Setter Property="IsSynchronizedWithCurrentItem" Value="False"/>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding Path=DropDownValues, Mode=OneWay}"/>
<Setter Property="IsDropDownOpen" Value="True" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
<DataGridTextColumn Header="Column 2"
Binding="{Binding Path=Col2, Mode=TwoWay, ValidatesOnDataErrors=True}"
Width="*"/>
</DataGrid.Columns>
</DataGrid>
I can't imagine what I'm doing wrong. I saw this other link that seems to describe the same problem I am having, but the solution that worked for them doesn't seem to work for me; I added the SelectedValueBinding and SelectedValuePath, but the behavior did not change.
Remove Mode=TwoWay from the bindings.
The problem is caused by a bug in the clipboard and automation support. That works by setting a special property on the cell to ClipboardContentBinding and then reading the value. If that binding is two-way, it winds up sometimes pushing an old value from the special property back to the view model, and validation errors seem to trigger this behavior. DataGridBoundColumns and DataGridComboBoxColumns will supply Binding or SelectedItemBinding if ClipboardContentBinding is null, so you’ll get this bug if you set either of those to a TwoWay binding.
If you don’t set Mode, it will be Default and use the default from the property, which is TwoWay for TextBox.Text and ComboBox.SelectedItem but OneWay for the special clipboard property.
I have a datagrid that is bound to an observable collection from my viewmodel. This all works fine and displays my data in the datagrid.
What i need to do now is validate some columns when the user chnages the text. I am using the IDataErrorInfo to do this.
If i do the following:-
**<TextBox
Width="100"
Text="{Binding Path=CallCode,
Mode=TwoWay,
ValidatesOnDataErrors=True,
UpdateSourceTrigger=PropertyChanged }"/>**
This works and triggers the validation code in my viewmodel, however if i add this code to the datagrid as below it doesnt do anything!:-
<Border x:Name="body"
DockPanel.Dock="Top"
Grid.Row="2"
Grid.Column="0">
<!-- Results -->
<DataGrid x:Name="Results"
ItemsSource="{Binding CallCodesList}"
AutoGenerateColumns="False"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
CanUserAddRows="False">
<DataGrid.Columns >
**<DataGridTextColumn
Header="Call Code"
CanUserSort="True"
Width="100"
Binding="{Binding CallCode,
ValidatesOnDataErrors=True,
UpdateSourceTrigger=PropertyChanged />**
<DataGridCheckBoxColumn Width="70"
Binding="{Binding Path=HasSpeech}"
Header="Speech"
IsThreeState="True">
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType="CheckBox">
<Setter Property="IsChecked" Value="{Binding HasSpeech}" />
</Style>
</DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>
</DataGrid>
</Border>
Is there someting i am missing or can it not see something because it is in a datagrid, this is all new so currently stuck :(
Any help with this would be great.
It seams that the code is fine, i don't know if the wpftoolkit's data grid allow IDataErrorInfo validation, but in this article (Validation in WPF Toolkit’s DataGrid) you can see a good example of using validation on wpftoolkit's data grid, but using the IDataError interface way.
I hope this help to you...
I have the following ListBox:
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
SelectionChanged="ListBoxContainerSelectionChanged"
ItemsSource="{Binding Movies}"
ItemContainerStyle="{StaticResource HeaderListBoxItemStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<Controls:MoviesItemControl Header="{Binding Title}"
Detail="{Binding FormattedDescription}"
Rating="{Binding Rating}"
Opacity="{Binding IsSuppressed, Converter={StaticResource DimIfTrueConverter}}"
IsEnabled="{Binding IsSuppressed, Converter={StaticResource InverseBooleanConverter}}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I'm trying to set the Disabled state of ListBoxItems that are 'Suppressed' (Movies with no description found). I have a property which I am able to bind to my individual control, but I want them to not be selectable in the actual list. (And use the disabled state included in my ItemsContainerStyle)
I have seen a few implementations on SO using Trigger, but that does not seem to be available in WP7, and I would prefer to not have to create a different style for each control so that they bind properly.
Any ideas?
See the following question: WP7 - Databind ListboxItem's IsEnabled Property
Which in turn links to this: Better SetterValueBindingHelper makes Silverlight Setters better-er!
I tried out SetterValueBindingHelper by David Anson for this specific scenario and it worked great. All you have to do is to add SetterValueBindingHelper.cs to your project and then you can bind IsEnabled in the setter like this
<Style x:Key="HeaderListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="delay:SetterValueBindingHelper.PropertyBinding">
<Setter.Value>
<delay:SetterValueBindingHelper Property="IsEnabled"
Binding="{Binding IsSuppressed}"/>
</Setter.Value>
</Setter>
</Style>