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>
Related
I have the following markup:
<StackPanel Grid.Row="0" Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Visibility="{Binding OrgListVisibility}">
<Label Content="Org:" />
<ComboBox ItemsSource="{Binding OrgSelectList, NotifyOnSourceUpdated=True}" SelectedValuePath="Key" DisplayMemberPath="Value" SelectedItem="{Binding OrgId}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding BranchListVisibility}">
<TextBlock Text="Branch:" Style="{StaticResource FormLabel}" />
<ComboBox x:Name="BranchList" ItemsSource="{Binding BranchSelectList}" SelectedValuePath="Key" DisplayMemberPath="Value" SelectedItem="{Binding BranchId}" />
</StackPanel>
</StackPanel>
Yet when I run the app, only the text from the TextBlock is visible, and not that of the Label. The latter is in the Visual Tree, with a TextBlock deep down, but that is as far as I can see.
AS REQUESTED: Here is the style for FormLabel:
<Style TargetType="TextBlock" x:Key="FormLabel">
<Setter Property="Height" Value="20" />
<Setter Property="Margin" Value="10" />
<Setter Property="TextAlignment" Value="Right" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
A SIMILAR PROBLEM:
I found an almost similar problem with a combobox when I bound it to a collection of instances of a generic class. The items' text simply did not show, but they were present in the comboboxes. Selecting on the one by knowing the position of my sought item correctly cascaded to the 2nd combobox, which had visible items, and I could see the correct but invisible item had been selected.
As soon as I change the item source to a list of non-generic objects, the items in the dropdown were visible again.
The code looks fine and as you have mentioned in the comments section that it takes layout space then it may very well happen that the color of your label and the background color of the containing layout be same.
To troubleshoot this, try giving some different background and foreground colors e.g. red or blue to the Label. Hope this helps
Ctrl+Q -> Live Visual Tree
Then hit the "pick element" button and select your label. Check the following properties:
Visibility
Opacity
Content
Also check the child elements of the Label. Setting the Content should result in a tree like this:
If a default style has changed the control template, you might not see the TextBlock as a child here. Also drill into the TextBlock and make sure it has the right Text property, then make sure it and all its parents have the right Opacity and Visibility . Also make sure that the inner TextBlock has space allocated to it by selecting it and turning on the highlighting feature in the live visual tree window.
Can you try this code to see if it works?
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"
Orientation="Horizontal" Visibility="{Binding OrgListVisibility}">
<Label Content="Org:" />
<ComboBox ItemsSource="{Binding OrgSelectList, NotifyOnSourceUpdated=True}"
SelectedValuePath="Key"
DisplayMemberPath="Value"
SelectedItem="{Binding OrgId}" />
</StackPanel>
<StackPanel Grid.Column="1"
Orientation="Horizontal" Visibility="{Binding BranchListVisibility}">
<TextBlock Text="Branch:" Style="{StaticResource FormLabel}" />
<ComboBox x:Name="BranchList"
ItemsSource="{Binding BranchSelectList}"
SelectedValuePath="Key"
DisplayMemberPath="Value"
SelectedItem="{Binding BranchId}" />
</StackPanel>
</Grid>
The Label would take up layout space while not being visible when its Visibility == Hidden. You should check and make sure that your application does not define a global style (one with no Key) for TargetType="Label" where this value could be set:
<Style TargetType="Label"> !!!note that this has no 'Key' associated
[...]
<Setter Property="Visibility" Value="Hidden" />
[...]
</Style>
This would not need to be in the same xaml file in order to be automatically applied, you should check the global dictionary or any other ResourceDictionary linked in the file.
I had the same problem. It turned out that the label Height was too small. Increased the height and its content became visible.
I have a check box where the property ischecked is bounded to another checkbox. In the resources block i've set a style that sets the event triger for a checkbox. Here's the code:
<Style x:Key="cbClickEvent" TargetType="{x:Type CheckBox}">
<EventSetter Event="Click" Handler="CheckBox_Click"/>
</Style>
<StackPanel Grid.Column="0" Grid.Row="1">
<CheckBox x:Name="cbAll" Content=" All" VerticalAlignment="Center"/>
<CheckBox Content=" MyCB" VerticalAlignment="Center" IsChecked="{Binding ElementName=cbAll, Path=IsChecked, Mode=OneWay}" Style="{StaticResource cbClickEvent}"/>
</StackPanel>
When i click the checkbox MyCB the event is triggered, but not when i clicked the checkbox All. What am i missing?
This is because when you click on the "All" checkbox the value gets transfered to the "MyCB" checkbox via binding. But in the style you subscribe to the Clickevent which obviously is not firing in this case because you don't actually click on the "MyCB" checkbox (you click on "All").
What you can do is, instead of subscribing to the Click event, you can subscribe to the Checked and Unchecked events:
<EventSetter Event="Checked" Handler="CheckBox_Checked"/>
<EventSetter Event="Unchecked" Handler="CheckBox_Unchecked"/>
2 possible solitions:
1) Add the
Style="{StaticResource cbClickEvent}"
To the cbAll CheckBox
2) Remove that line from the MyCB CheckBox and remove the x:Key property from the style. It will look like this:
<Window.Resources>
<Style TargetType="{x:Type CheckBox}">
<EventSetter Event="Click" Handler="CheckBox_Click"/>
</Style>
</Window.Resources>
<StackPanel Grid.Column="0" Grid.Row="1">
<CheckBox x:Name="cbAll"
Content=" All"
VerticalAlignment="Center" />
<CheckBox Content=" MyCB"
VerticalAlignment="Center"
IsChecked="{Binding ElementName=cbAll, Path=IsChecked, Mode=OneWay}" />
</StackPanel>
I Wish the treeviewitem to overlap the other items when i mouse hover it.
To do this i made the parent element (in my case its Border) within the HierarchicalDataTemplate to have the ZIndex as 0 and changed this value to 1 when the user hovers the mouse in the HierarchicalDataTemplate.Triggers section
<HierarchicalDataTemplate DataType="{x:Type d:MyClass}">
<Border Name="brd" CornerRadius="5" BorderThickness="1" Padding="3" Margin="0,0,60,0" Panel.ZIndex="0" >
<StackPanel Orientation="Horizontal" Margin="0,0,0,0" >
<Image Source="../Images/icon.jpg" Height="30"></Image>
<TextBlock TextAlignment="Center" Text="{Binding Text}"
Margin="3,0,10,0" >
</TextBlock>
<Image Margin="0,0,3,0"
Source="../Images/Img1.jpg" Height="30" />
<Image Margin="0,0,0,0"
Source="../Images/Img2" Height="30"/>
</StackPanel>
</Border>
<HierarchicalDataTemplate.Triggers>
<Trigger SourceName="brd" Property="IsMouseOver" Value="True">
<Setter TargetName="brd" Property="Panel.ZIndex" Value="1"></Setter>
</Trigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
The whole idea to implement this was:
Whenever the user hovers the mouse over a treeviewitem, the item should overlap the other controls and should be completely visible. Example: if the item is a long text, then the user should not be forced to use the scroll bar, rather if he just points it the item should be overlapping the other controls to display the complete item.
But i couldn't achieve this using the above triggers.
Please help me doing this.
Did you try using a ToolTip? I didn't try it myself but after seeing this I'm convinced that it's possible to define a DataTemplate which can be used at this property so the item is shown the way you like.
I hope this helps.
Regards
Below is a template that works from a binding perspective, but the error template doesn't show, and without an AdornedElementPlaceholder the result looks a bit garish.
My view models implement IDataErrorInfo, and normally I would trigger the error template by having ValidatesOnError=True as part of my binding. This particular view model is display only, so the IDataErrorInfo indexer is never invoked. I do have a number of useful properties related to validation though, including a boolean IsValid property as well as IDataErrorInfo.Error, both of which properly respond to the view model being invalid.
Should I translate the error to a ValidationResult and trigger it that way? Or is there something easier?
Cheers,
Berryl
current template
<!-- FooterViewModel DataTemplate -->
<DataTemplate DataType="{x:Type model:FooterViewModel}">
<Label x:Name="lblTotalTime"
Style="{StaticResource FooterStyle}"
Content="{Binding TotalTime, Converter={StaticResource TotalAmountConv}}" >
<Label.ToolTip>
<TextBlock Text="{Binding FeedbackMessage}" ></TextBlock>
</Label.ToolTip>
<Validation.ErrorTemplate>
<ControlTemplate>
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Right" Text=" *"
Foreground="Red"
FontWeight="Bold" FontSize="16"
/>
<Border BorderBrush="Red" BorderThickness="1">
<AdornedElementPlaceholder Name="placeholder"></AdornedElementPlaceholder>
</Border>
</DockPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
</Label>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsValid}" Value="False">
<Setter TargetName="lblTotalTime" Property="Control.BorderBrush" Value="Red"/>
<Setter TargetName="lblTotalTime" Property="Control.BorderThickness" Value="1"/>
<Setter TargetName="lblTotalTime" Property="Control.Background" Value="LightYellow"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
UPDATE
Ok, I am getting IDataErrorInfo to kick in just by changing my binding to include ValidatesOnErrors, BUT the error template still does not show up.
Here is the binding
<ItemsControl
ItemsSource="{Binding Path=FooterViewModels, Mode=OneWay, ValidatesOnDataErrors=True}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
By default, the validation is only run when the Source of the binding is updated. In your ItemsControl.ItemsSource binding the Sources is your FooterViewsModels, which obviously will never be updated (because you have Mode=OneWay).
You can use the DataErrorValidationRule.ValidatesOnTargetUpdated to run the validation when the target is updated as well. The link gives an example.
Keep in mind that the Binding.ValidatesOnDataErrors property is is just a short cut for adding an instance of DataErrorValidationRule to the Binding.ValidationRules collection.
Finally, the control that the binding is defined one will have the Validation.Errors. In your case, that is the ItemsControl, not the items inside it. So, I believe you need to add the DataErrorValidationRule to your Label.Content binding. Or you need to define your ErrorTemplate on the ItemsControl, depending on what you are going for.
I wanted to bind Width of a column header to the Width of the header defined. However the code doesn't work. If I specify the Width explicitly (Width="100"), it works fine. Can someone shed some light and tell me what is wrong with the code below?
<dataGrid:DataGridTemplateColumn x:Name="pdpCol" Width="100">
<dataGrid:DataGridTemplateColumn.Header>
<Grid HorizontalAlignment="Stretch">
<TextBlock Text="PDP" VerticalAlignment="Center" HorizontalAlignment="Center"
TextWrapping="Wrap" Width="{Binding ElementName=pdpCol,Path=ActualWidth }" TextAlignment="Center" />
</Grid>
</dataGrid:DataGridTemplateColumn.Header>
</dataGrid:DataGridTemplateColumn>
Remove the HorizontalAlignment="Center" from the TextBlock or set the property to Stretch. Then the TextBlock will consume all available width automatically. Furthermore, if you don't show anything else than the textblock, then remove the grid and use just the TextBlock. You also need to set HeaderTemplate rather the Header directly.
<dataGrid:DataGridTemplateColumn x:Name="pdpCol" Width="100" Header="PDP">
<dataGrid:DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" TextAlign="Center" />
</DataTemplate>
</dataGrid:DataGridTemplateColumn.HeaderTemplate>
</dataGrid:DataGridTemplateColumn>
Best Regards,
Oliver Hanappi
Try the markup below. Please note the use of HeaderStyle to stretch the template and HeaderTemplate to actually define the visual template for your Header="PDP" item.
<dataGrid:DataGridTemplateColumn x:Name="pdpCol" Width="100" Header="PDP">
<dataGrid:DataGridTemplateColumn.HeaderStyle>
<Style TargetType="{x:Type Primitives:DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</dataGrid:DataGridTemplateColumn.HeaderStyle>
<dataGrid:DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" TextAlignment="Center" />
</DataTemplate>
</dataGrid:DataGridTemplateColumn.HeaderTemplate>
</dataGrid:DataGridTemplateColumn>
Check if ActualWidth is being set, I think it will work if you just use Path=Width.