enhance: add HighlightTextBrush prop for HighlightTextBlock
This commit is contained in:
1 parent
12c6c39424
commit
534f1ef961
6 files changed
+34
-9
No files matched your search
@@ -1306,6 +1306,10 @@
|
|||||||
<Style x:Key="TextBlockBoldBaseStyle" BasedOn="{StaticResource TextBlockBaseStyle}" TargetType="TextBlock">
|
<Style x:Key="TextBlockBoldBaseStyle" BasedOn="{StaticResource TextBlockBaseStyle}" TargetType="TextBlock">
|
||||||
<Setter Property="FontWeight" Value="Bold" />
|
<Setter Property="FontWeight" Value="Bold" />
|
||||||
</Style>
|
</Style>
|
||||||
|
<Style x:Key="HighlightTextBlockBaseStyle" TargetType="hc:HighlightTextBlock">
|
||||||
|
<Setter Property="HighlightBrush" Value="{DynamicResource PrimaryBrush}" />
|
||||||
|
<Setter Property="HighlightTextBrush" Value="{DynamicResource TextIconBrush}" />
|
||||||
|
</Style>
|
||||||
<Style x:Key="LabelBaseStyle" TargetType="Label">
|
<Style x:Key="LabelBaseStyle" TargetType="Label">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}" />
|
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}" />
|
||||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
||||||
@@ -3280,6 +3284,7 @@
|
|||||||
<Setter Property="FontSize" Value="{StaticResource SubHeadFontSize}" />
|
<Setter Property="FontSize" Value="{StaticResource SubHeadFontSize}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="TextBlockDefaultBold" BasedOn="{StaticResource TextBlockBoldBaseStyle}" TargetType="TextBlock" />
|
<Style x:Key="TextBlockDefaultBold" BasedOn="{StaticResource TextBlockBoldBaseStyle}" TargetType="TextBlock" />
|
||||||
|
<Style BasedOn="{StaticResource HighlightTextBlockBaseStyle}" TargetType="hc:HighlightTextBlock" />
|
||||||
<Style BasedOn="{StaticResource LabelBaseStyle}" TargetType="Label">
|
<Style BasedOn="{StaticResource LabelBaseStyle}" TargetType="Label">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
|
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
|
||||||
<Setter Property="BorderThickness" Value="1" />
|
<Setter Property="BorderThickness" Value="1" />
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<Image Width="16" Height="16" Source="{Binding ImageName}"/>
|
<Image Width="16" Height="16" Source="{Binding ImageName}"/>
|
||||||
<hc:HighlightTextBlock Margin="6,0,0,0" SourceText="{ex:Lang Key={Binding Name}}" QueriesText="{Binding QueriesText}" HighlightBrush="#f06632" />
|
<hc:HighlightTextBlock Margin="6,0,0,0" SourceText="{ex:Lang Key={Binding Name}}" QueriesText="{Binding QueriesText}"/>
|
||||||
<Path Visibility="{Binding IsNew,Converter={StaticResource Boolean2VisibilityConverter}}" VerticalAlignment="Center" Data="{StaticResource NewGeometry}" Stretch="Uniform" Margin="10,0,0,0" Width="30" Height="14" Fill="{DynamicResource DangerBrush}"/>
|
<Path Visibility="{Binding IsNew,Converter={StaticResource Boolean2VisibilityConverter}}" VerticalAlignment="Center" Data="{StaticResource NewGeometry}" Stretch="Uniform" Margin="10,0,0,0" Width="30" Height="14" Fill="{DynamicResource DangerBrush}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ namespace HandyControl.Controls
|
|||||||
new PropertyMetadata(null, OnQueriesTextChanged));
|
new PropertyMetadata(null, OnQueriesTextChanged));
|
||||||
|
|
||||||
public static readonly DependencyProperty HighlightBrushProperty =
|
public static readonly DependencyProperty HighlightBrushProperty =
|
||||||
DependencyProperty.Register("HighlightBrush", typeof(Brush), typeof(HighlightTextBlock),
|
DependencyProperty.Register("HighlightBrush", typeof(Brush), typeof(HighlightTextBlock));
|
||||||
new PropertyMetadata(Brushes.Yellow));
|
|
||||||
|
public static readonly DependencyProperty HighlightTextBrushProperty =
|
||||||
|
DependencyProperty.Register("HighlightTextBrush", typeof(Brush), typeof(HighlightTextBlock));
|
||||||
|
|
||||||
private static void OnSourceTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
private static void OnSourceTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
||||||
((HighlightTextBlock) d).RefreshInlines();
|
((HighlightTextBlock) d).RefreshInlines();
|
||||||
@@ -64,6 +66,12 @@ namespace HandyControl.Controls
|
|||||||
set => SetValue(HighlightBrushProperty, value);
|
set => SetValue(HighlightBrushProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Brush HighlightTextBrush
|
||||||
|
{
|
||||||
|
get => (Brush) GetValue(HighlightTextBrushProperty);
|
||||||
|
set => SetValue(HighlightTextBrushProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
private void RefreshInlines()
|
private void RefreshInlines()
|
||||||
{
|
{
|
||||||
Inlines.Clear();
|
Inlines.Clear();
|
||||||
@@ -97,12 +105,10 @@ namespace HandyControl.Controls
|
|||||||
private Run GetHighlightRun(string highlightText)
|
private Run GetHighlightRun(string highlightText)
|
||||||
{
|
{
|
||||||
var run = new Run(highlightText);
|
var run = new Run(highlightText);
|
||||||
run.SetBinding(TextElement.BackgroundProperty, new Binding
|
|
||||||
{
|
run.SetBinding(TextElement.BackgroundProperty, new Binding(nameof(HighlightBrush)) { Source = this });
|
||||||
Source = this,
|
run.SetBinding(TextElement.ForegroundProperty, new Binding(nameof(HighlightTextBrush)) { Source = this });
|
||||||
Path = new PropertyPath(nameof(HighlightBrush)),
|
|
||||||
Mode = BindingMode.OneWay
|
|
||||||
});
|
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:hc="clr-namespace:HandyControl.Controls"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
|
|
||||||
<Style x:Key="TextBlockBaseStyle" TargetType="TextBlock">
|
<Style x:Key="TextBlockBaseStyle" TargetType="TextBlock">
|
||||||
@@ -11,4 +12,9 @@
|
|||||||
<Setter Property="FontWeight" Value="Bold"/>
|
<Setter Property="FontWeight" Value="Bold"/>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<Style x:Key="HighlightTextBlockBaseStyle" TargetType="hc:HighlightTextBlock">
|
||||||
|
<Setter Property="HighlightBrush" Value="{DynamicResource PrimaryBrush}"/>
|
||||||
|
<Setter Property="HighlightTextBrush" Value="{DynamicResource TextIconBrush}"/>
|
||||||
|
</Style>
|
||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:hc="clr-namespace:HandyControl.Controls"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
|
|
||||||
<!--默认样式-->
|
<!--默认样式-->
|
||||||
@@ -49,4 +50,6 @@
|
|||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="TextBlockDefaultBold" BasedOn="{StaticResource TextBlockBoldBaseStyle}" TargetType="TextBlock"/>
|
<Style x:Key="TextBlockDefaultBold" BasedOn="{StaticResource TextBlockBoldBaseStyle}" TargetType="TextBlock"/>
|
||||||
|
|
||||||
|
<Style BasedOn="{StaticResource HighlightTextBlockBaseStyle}" TargetType="hc:HighlightTextBlock"/>
|
||||||
|
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -1306,6 +1306,10 @@
|
|||||||
<Style x:Key="TextBlockBoldBaseStyle" BasedOn="{StaticResource TextBlockBaseStyle}" TargetType="TextBlock">
|
<Style x:Key="TextBlockBoldBaseStyle" BasedOn="{StaticResource TextBlockBaseStyle}" TargetType="TextBlock">
|
||||||
<Setter Property="FontWeight" Value="Bold" />
|
<Setter Property="FontWeight" Value="Bold" />
|
||||||
</Style>
|
</Style>
|
||||||
|
<Style x:Key="HighlightTextBlockBaseStyle" TargetType="hc:HighlightTextBlock">
|
||||||
|
<Setter Property="HighlightBrush" Value="{DynamicResource PrimaryBrush}" />
|
||||||
|
<Setter Property="HighlightTextBrush" Value="{DynamicResource TextIconBrush}" />
|
||||||
|
</Style>
|
||||||
<Style x:Key="LabelBaseStyle" TargetType="Label">
|
<Style x:Key="LabelBaseStyle" TargetType="Label">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}" />
|
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}" />
|
||||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
||||||
@@ -3280,6 +3284,7 @@
|
|||||||
<Setter Property="FontSize" Value="{StaticResource SubHeadFontSize}" />
|
<Setter Property="FontSize" Value="{StaticResource SubHeadFontSize}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="TextBlockDefaultBold" BasedOn="{StaticResource TextBlockBoldBaseStyle}" TargetType="TextBlock" />
|
<Style x:Key="TextBlockDefaultBold" BasedOn="{StaticResource TextBlockBoldBaseStyle}" TargetType="TextBlock" />
|
||||||
|
<Style BasedOn="{StaticResource HighlightTextBlockBaseStyle}" TargetType="hc:HighlightTextBlock" />
|
||||||
<Style BasedOn="{StaticResource LabelBaseStyle}" TargetType="Label">
|
<Style BasedOn="{StaticResource LabelBaseStyle}" TargetType="Label">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
|
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}" />
|
||||||
<Setter Property="BorderThickness" Value="1" />
|
<Setter Property="BorderThickness" Value="1" />
|
||||||
|
|||||||
Reference in new issue
Block a user