Why is this tooltip still enabled? - c#

I am working on a WPF app, and I am trying to make a tooltip conditionally enabled. It was being odd, and I realized that even when I explicitly set the tooltip to not enabled (ToolTipService.IsEnabled="False"), the tooltip still shows up. Can anyone figure out what is going on here?
<TextBlock Grid.Row="2"
Grid.Column="0"
VerticalAlignment="Center"
FontSize="15"
ToolTipService.IsEnabled="False"
Visibility="{Binding IsConnected, Converter={StaticResource BooleanToVisibilityConverter}}">
<fa:ImageAwesome Icon="{Binding Path=BatteryLevelIcon, UpdateSourceTrigger=PropertyChanged}"
Height="20"
Width="20"
Foreground="Green"
Visibility="{Binding IsConnected, Converter={StaticResource BooleanToVisibilityConverter}}" />
<ToolTipService.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}%">
<Binding Path="BatteryPercentage" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ToolTipService.ToolTip>
</TextBlock>

Set ToolTipService.ShowOnDisabled = false;
ToolTipService.ShowOnDisabled

Related

Why does this custom style for TextBox break my Text binding? [duplicate]

I have successfully created a textbox that displays / collapses an error message depending upon a validation rule set in its model / vm. The code goes like this for the email for ex.:
<StackPanel Grid.Row="3" Grid.Column="1">
<TextBox MaxLength="200" x:Name="mailTextBox"
Style="{StaticResource SectionEditPropertyTextBox}"
Text="{Binding Email, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
<ContentPresenter Visibility="{Binding ElementName=mailTextBox, Path=(Validation.HasError), Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=True }"
Content="{Binding ElementName=mailTextBox, Path=(Validation.Errors).CurrentItem}"
HorizontalAlignment="Left">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<Label Style="{StaticResource SectionEditErrorLabel}" Content="{Binding Path=ErrorContent}"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
</StackPanel>
Since I have a bunch of these, I would have liked to put all of this in a control template and relocate this in a common resource file.
My template looks like this:
<ControlTemplate x:Key="FormTextBox" TargetType="{x:Type TextBox}">
<StackPanel Grid.Row="{TemplateBinding Grid.Row}" Grid.Column="{TemplateBinding Grid.Column}">
<TextBox x:Name="validableText" MaxLength="{TemplateBinding MaxLength}"
Style="{StaticResource SectionEditPropertyTextBox}"
Text="{TemplateBinding Text}" />
<ContentPresenter Visibility="{Binding ElementName=validableText, Path=(Validation.HasError), Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=True }"
Content="{Binding ElementName=validableText, Path=(Validation.Errors).CurrentItem}"
HorizontalAlignment="Left">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<Label Style="{StaticResource SectionEditErrorLabel}" Content="{Binding Path=ErrorContent}"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
</StackPanel>
</ControlTemplate>
and I link to it like this:
<TextBox Grid.Row="3" Grid.Column="1" MaxLength="200" Template="{StaticResource FormTextBox}"
Text="{Binding Email, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
Unfortunately, it doesn't perform any validation so the binding must be broken somehow...
Please advise...
Thanks.
You won't need the Grid.Row and Grid.Column bindings in the Template StackPanel since the StackPanel won't be the direct child of a Grid anyway,
TemplateBinding is always a OneWay binding so the Text property for the Templated TextBox will never get updated. Change it to a regular Binding with RelativeSource and TwoWay
Change ElementName=validableText to RelativeSource={RelativeSource TemplatedParent} in the bindings for ContentPresenter since we want to perform the validation check on the Templated TextBox and not the TextBox inside the Template.
<ControlTemplate x:Key="FormTextBox" TargetType="{x:Type TextBox}">
<StackPanel>
<TextBox x:Name="validableText"
MaxLength="{TemplateBinding MaxLength}"
Style="{StaticResource SectionEditPropertyTextBox}"
Text="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=Text,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
<ContentPresenter Visibility="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(Validation.HasError),
Converter={StaticResource BooleanToVisibilityConverter}
ConverterParameter=True}"
Content="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(Validation.Errors).CurrentItem}"
HorizontalAlignment="Left">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<Label Style="{StaticResource SectionEditErrorLabel}" Content="{Binding Path=ErrorContent}"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
</StackPanel>
</ControlTemplate>
On a side note, another alternative that you have here is to create a UserControl with the original piece of Xaml that you had. You could introduce the Dependency Properties needed for your scenario (Text etc.). It would only require small changes.

WPF: Align TextBlock with different font sizes at top

I need to align two text elements of different font sizes at the top line.
All I managed so far is either this :
Resulting from this code:
<Canvas VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True">
<StackPanel x:Name="RemainingTimeDisplay" Orientation="Horizontal" VerticalAlignment="Top">
<StackPanel.Margin>
<MultiBinding Converter="{StaticResource CenterConverter}">
<Binding ElementName="RemainingTimeDisplay" Path="ActualWidth"/>
<Binding ElementName="RemainingTimeDisplay" Path="ActualHeight"/>
</MultiBinding>
</StackPanel.Margin>
<!--<Run FontSize="360" Text="{Binding RemainingTime.Minutes, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
<Run FontSize="128" Text="{Binding RemainingTime.Seconds, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>-->
<TextBlock FontSize="360" Text="{Binding RemainingTime.Minutes, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
<TextBlock FontSize="128" Text="{Binding RemainingTime.Seconds, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
</StackPanel>
</Canvas>
Or:
<Canvas VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True">
<StackPanel x:Name="RemainingTimeDisplay" Orientation="Horizontal" VerticalAlignment="Top">
<StackPanel.Margin>
<MultiBinding Converter="{StaticResource CenterConverter}">
<Binding ElementName="RemainingTimeDisplay" Path="ActualWidth"/>
<Binding ElementName="RemainingTimeDisplay" Path="ActualHeight"/>
</MultiBinding>
</StackPanel.Margin>
<TextBlock FontFamily="Roboto" VerticalAlignment="Top">
<TextBlock FontSize="360" Text="{Binding RemainingTime.Minutes, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
<TextBlock FontSize="128" Text="{Binding RemainingTime.Seconds, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
</TextBlock>
</StackPanel>
</Canvas>
I tried also some more things, that I don't repeat here in code. I tried using "run" as a child of on single TextBlock for both text elements and I (actually started) tried without the TextBlock that encloses the other two.
So I tried a lot, I googled a lot - and I'm still not where I want to be.
Any hint would be really appreciated!
Thanks,
Marcus
Try the following:
<TextBlock FontSize="360"
Text="00"
LineHeight="360"
LineStackingStrategy="BlockLineHeight" />
<TextBlock FontSize="128"
LineHeight="360"
LineStackingStrategy="BlockLineHeight">
<Run Text="00" BaselineAlignment="Top" />
</TextBlock>

DependencyProperty.UnsetValue using template and MultiBinding

Anyone knows why I receive the error: "DependencyProperty.UnsetValue" when I call my Command through the Template
This is my template:
<DataTemplate x:Key="MenuComboBoxItemTemplate" DataType="ComboBox">
<DockPanel>
<TextBlock DockPanel.Dock="Left" Text="{Binding Text.Display}" />
<Button x:Name="RemoveButton"
Style="{StaticResource DeleteButton}"
DockPanel.Dock="Right"
ToolTip="Delete"
HorizontalAlignment="Right"
Padding="2"
Margin="3,0,0,0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl},AncestorLevel=1}, Path=DataContext.RemoveMenuItemCommand}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource MultiValueConverter}">
<Binding Path="Name" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type menus:MenuComboBox}}" />
<Binding />
</MultiBinding>
</Button.CommandParameter>
<Image Source="{dx:DXImageOffice2013 Image=Delete_16x16.png}" />
</Button>
</DockPanel>
</DataTemplate>
My combobox:
<menus:MenuComboBox
x:Name="MyItems"
Grid.Column="0"
Grid.Row="2"
Padding="6,3,5,3"
BorderThickness="1"
Text="{Binding MyItems, UpdateSourceTrigger=LostFocus}"
ItemTemplate="{StaticResource MenuComboBoxItemTemplate}"
ItemsSource="{Binding Menus[MyItems].Items}"
NewMenuItemCommand="{Binding AddMenuItemCommand}"
GotFocusCommand="{Binding GotFocusCommand}" />
I am stuck on it :(

Can't get rid of red validation border around listbox control (IDataErrorInfo)

I have removed red border from styling properties but it still remains on listbox, how can I fix this?
As you can see no red border is this a default thing?
<Window.Resources>
<ControlTemplate x:Key="eTemplate">
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Right" Foreground="Black" FontSize="14" Text="{Binding ElementName=adorned,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" >
</TextBlock>
<Border BorderThickness="0">
<AdornedElementPlaceholder x:Name="adorned"/>
</Border>
</DockPanel>
</ControlTemplate>
</Window.Resources>
.
<ListBox HorizontalAlignment="Left" Height="73" Margin="449,275,0,0" VerticalAlignment="Top" Width="94" Name="LocationTo" SelectionChanged="listBox_SelectionChanged">
<ListBox.SelectedIndex>
<Binding Path="LocationTo" ValidatesOnDataErrors="True" UpdateSourceTrigger="PropertyChanged"/>
</ListBox.SelectedIndex>
<ListBoxItem Content="Conn Junction"/>
<ListBoxItem Content="Multhy Pass"/>
<ListBoxItem Content="Suddean Halt"/>
<ListBoxItem Content="End Terminal"/>
</ListBox>
.
<TextBox Height="27" Validation.ErrorTemplate="{StaticResource ResourceKey=eTemplate}" HorizontalAlignment="Left" Margin="88,62,0,0" Name="FName" VerticalAlignment="Top" Width="127" FontSize="12" TextChanged="FName_TextChanged">
<TextBox.Text>
<Binding Path="FName" ValidatesOnDataErrors="True" UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
</TextBox>

Wpf - Speed ListBox

I've got a Wpf Application and I'm having some speed/time issues. I've got a Grid with 2 columns. The left column contains a panel with a ListBox, and when one of the items is selected it creates a new panel and sets it at the right column of the Grid. So I've got a fixed panel on the left and a changing panel on the right.
My right panel contains some details and a ListBox. When I keep changing the right panel (change selection of the left panel) it gets really slow and UI freezes. I was able to find the issue, and it was with my ListBox. It has a complex ItemTemplate and this could explain why it is slow.
My ListBox ItemTemplate:
<DataTemplate>
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="{Binding ., Converter={StaticResource MyConverter}}">
<TextBox Style="{StaticResource MyStyle}" Text="{Binding Property, Converter={StaticResource MyConverter}}" HorizontalAlignment="{Binding ., Converter={StaticResource MyConverter}}" FontSize="10" Visibility="{Binding Property, Converter={StaticResource MyConverter}}"/>
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="{Binding ., Converter={StaticResource MyConverter}}">
<Border Padding="8" CornerRadius="10,10,10,10" Background="{Binding ., Converter={StaticResource MyConverter}}">
<StackPanel Orientation="Vertical">
<TextBox Style="{StaticResource MyStyle}" Text="{Binding Property}" Visibility="{Binding ., Converter={StaticResource MyConverter}}" FontSize="14" FontWeight="DemiBold" TextWrapping="Wrap" HorizontalAlignment="{Binding ., Converter={StaticResource MyConverter}}"/>
<StackPanel Orientation="Vertical" Visibility="{Binding Property, Converter={StaticResource MyConverter}}" HorizontalAlignment="Center">
<Image Source="{Binding Property, Converter={StaticResource MyConverter}}" MaxWidth="800" MaxHeight="200" Visibility="{Binding Property, Converter={StaticResource MyConverter}}"/>
<Image gif:ImageBehavior.AnimatedSource="ImageSource" Width="200" MaxHeight="200" Visibility="{Binding Property, Converter={StaticResource MyConverter}}"/>
</StackPanel>
<TextBox Style="{StaticResource MyStyle}" Text="{Binding ., Converter={StaticResource MyConverter}}" FontSize="14" TextWrapping="Wrap" VerticalAlignment="Stretch" HorizontalAlignment="{Binding ., Converter={StaticResource MyConverter}}"/>
</StackPanel>
</Border>
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="{Binding ., Converter={StaticResource MyConverter}}" Margin="0, 2, 0, 0" Visibility="{Binding Property, Converter={StaticResource MyConverter}}">
<Image Source="ImageSource" Margin="0,0,0,5" MaxHeight="10" VerticalAlignment="Center"/>
<TextBox Style="{StaticResource MyStyle}" Text="{Binding Property, Converter={StaticResource MyConverter}}" VerticalAlignment="Center" FontSize="10" TextWrapping="Wrap"/>
</StackPanel>
</StackPanel>
</DataTemplate>
Given this, what are some ways to speed things up?

Categories

Resources