fixed #827
This commit is contained in:
1 parent
aded2ab4e3
commit
c9fb7a2eb5
6 files changed
+57
-49
No files matched your search
@@ -43,7 +43,7 @@
|
|||||||
<TextBlock HorizontalAlignment="Left" Margin="5" Text="{ex:Lang Key={x:Static langs:LangKeys.Text},Converter={StaticResource StringRepeatConverter},ConverterParameter=20}" Style="{StaticResource TextBlockDefaultDanger}"/>
|
<TextBlock HorizontalAlignment="Left" Margin="5" Text="{ex:Lang Key={x:Static langs:LangKeys.Text},Converter={StaticResource StringRepeatConverter},ConverterParameter=20}" Style="{StaticResource TextBlockDefaultDanger}"/>
|
||||||
<TextBlock HorizontalAlignment="Left" Margin="5" Text="{ex:Lang Key={x:Static langs:LangKeys.Text},Converter={StaticResource StringRepeatConverter},ConverterParameter=20}" Style="{StaticResource TextBlockDefaultWarning}"/>
|
<TextBlock HorizontalAlignment="Left" Margin="5" Text="{ex:Lang Key={x:Static langs:LangKeys.Text},Converter={StaticResource StringRepeatConverter},ConverterParameter=20}" Style="{StaticResource TextBlockDefaultWarning}"/>
|
||||||
<TextBlock HorizontalAlignment="Left" Margin="5" Text="{ex:Lang Key={x:Static langs:LangKeys.Text},Converter={StaticResource StringRepeatConverter},ConverterParameter=20}" Style="{StaticResource TextBlockDefaultInfo}"/>
|
<TextBlock HorizontalAlignment="Left" Margin="5" Text="{ex:Lang Key={x:Static langs:LangKeys.Text},Converter={StaticResource StringRepeatConverter},ConverterParameter=20}" Style="{StaticResource TextBlockDefaultInfo}"/>
|
||||||
<TextBlock hc:TextBlockAttach.AutoTooltip="True" Width="300" HorizontalAlignment="Left" Margin="5" Text="{ex:Lang Key={x:Static langs:LangKeys.Text},Converter={StaticResource StringRepeatConverter},ConverterParameter=20}" Style="{StaticResource TextBlockDefaultSuccess}"/>
|
<TextBlock hc:TextBlockAttach.AutoTooltip="True" TextTrimming="CharacterEllipsis" Width="300" HorizontalAlignment="Left" Margin="5" Text="{ex:Lang Key={x:Static langs:LangKeys.Text},Converter={StaticResource StringRepeatConverter},ConverterParameter=20}" Style="{StaticResource TextBlockDefaultSuccess}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</hc:TransitioningContentControl>
|
</hc:TransitioningContentControl>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
|
using HandyControl.Tools.Helper;
|
||||||
|
|
||||||
namespace HandyControl.Controls
|
namespace HandyControl.Controls
|
||||||
{
|
{
|
||||||
@@ -15,13 +17,11 @@ namespace HandyControl.Controls
|
|||||||
{
|
{
|
||||||
if ((bool) e.NewValue)
|
if ((bool) e.NewValue)
|
||||||
{
|
{
|
||||||
ctl.TextTrimming = TextTrimming.WordEllipsis;
|
|
||||||
UpdateTooltip(ctl);
|
UpdateTooltip(ctl);
|
||||||
ctl.SizeChanged += TextBlock_SizeChanged;
|
ctl.SizeChanged += TextBlock_SizeChanged;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ctl.ClearValue(TextBlock.TextTrimmingProperty);
|
|
||||||
ctl.SizeChanged -= TextBlock_SizeChanged;
|
ctl.SizeChanged -= TextBlock_SizeChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,8 +46,23 @@ namespace HandyControl.Controls
|
|||||||
textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||||
var width = textBlock.DesiredSize.Width - textBlock.Margin.Left - textBlock.Margin.Right;
|
var width = textBlock.DesiredSize.Width - textBlock.Margin.Left - textBlock.Margin.Right;
|
||||||
|
|
||||||
ToolTipService.SetToolTip(textBlock,
|
if(textBlock.RenderSize.Width > width || textBlock.ActualWidth < width || CalcTextWidth(textBlock) > width)
|
||||||
textBlock.RenderSize.Width > width || textBlock.ActualWidth < width ? textBlock.Text : null);
|
{
|
||||||
|
ToolTipService.SetToolTip(textBlock, textBlock.Text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ToolTipService.SetToolTip(textBlock, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double CalcTextWidth(TextBlock textBlock)
|
||||||
|
{
|
||||||
|
var formattedText = TextHelper.CreateFormattedText(textBlock.Text, textBlock.FlowDirection,
|
||||||
|
new Typeface(textBlock.FontFamily, textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch),
|
||||||
|
textBlock.FontSize);
|
||||||
|
|
||||||
|
return formattedText.WidthIncludingTrailingWhitespace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Documents;
|
using System.Windows.Documents;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
|
using HandyControl.Tools.Helper;
|
||||||
|
|
||||||
namespace HandyControl.Controls
|
namespace HandyControl.Controls
|
||||||
{
|
{
|
||||||
@@ -201,27 +201,8 @@ namespace HandyControl.Controls
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NET40 || NET45 || NET451 || NET452 || NET46|| NET461
|
_formattedText = TextHelper.CreateFormattedText(Text, FlowDirection,
|
||||||
_formattedText = new FormattedText(
|
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), FontSize);
|
||||||
Text,
|
|
||||||
CultureInfo.CurrentUICulture,
|
|
||||||
FlowDirection,
|
|
||||||
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
|
|
||||||
FontSize, Fill);
|
|
||||||
#else
|
|
||||||
var source = PresentationSource.FromVisual(this);
|
|
||||||
var dpi = 1.0;
|
|
||||||
if (source?.CompositionTarget != null)
|
|
||||||
{
|
|
||||||
dpi = 96.0 * source.CompositionTarget.TransformToDevice.M11 / 96.0;
|
|
||||||
}
|
|
||||||
_formattedText = new FormattedText(
|
|
||||||
Text,
|
|
||||||
CultureInfo.CurrentUICulture,
|
|
||||||
FlowDirection,
|
|
||||||
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
|
|
||||||
FontSize, Fill, dpi);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UpdateFormattedText();
|
UpdateFormattedText();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Documents;
|
using System.Windows.Documents;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
|
using HandyControl.Tools.Helper;
|
||||||
|
|
||||||
namespace HandyControl.Controls
|
namespace HandyControl.Controls
|
||||||
{
|
{
|
||||||
@@ -129,27 +129,8 @@ namespace HandyControl.Controls
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NET40 || NET45 || NET451 || NET452 || NET46|| NET461
|
_formattedText = TextHelper.CreateFormattedText(Text, FlowDirection,
|
||||||
_formattedText = new FormattedText(
|
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), FontSize);
|
||||||
Text,
|
|
||||||
CultureInfo.CurrentUICulture,
|
|
||||||
FlowDirection,
|
|
||||||
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
|
|
||||||
FontSize, Foreground);
|
|
||||||
#else
|
|
||||||
var source = PresentationSource.FromVisual(this);
|
|
||||||
var dpi = 1.0;
|
|
||||||
if (source?.CompositionTarget != null)
|
|
||||||
{
|
|
||||||
dpi = 96.0 * source.CompositionTarget.TransformToDevice.M11 / 96.0;
|
|
||||||
}
|
|
||||||
_formattedText = new FormattedText(
|
|
||||||
Text,
|
|
||||||
CultureInfo.CurrentUICulture,
|
|
||||||
FlowDirection,
|
|
||||||
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
|
|
||||||
FontSize, Foreground, dpi);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UpdateFormattedText();
|
UpdateFormattedText();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -372,6 +372,7 @@
|
|||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ScreenHelper.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ScreenHelper.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\SecurityHelper.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\SecurityHelper.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\SingleOpenHelper.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\SingleOpenHelper.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\TextHelper.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\TokenizerHelper.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\TokenizerHelper.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\TouchDragMoveWindowHelper.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\TouchDragMoveWindowHelper.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ValidateHelper.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ValidateHelper.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace HandyControl.Tools.Helper
|
||||||
|
{
|
||||||
|
internal class TextHelper
|
||||||
|
{
|
||||||
|
public static FormattedText CreateFormattedText(string text, FlowDirection flowDirection, Typeface typeface, double fontSize)
|
||||||
|
{
|
||||||
|
#if NET40 || NET45 || NET451 || NET452 || NET46 || NET461
|
||||||
|
var formattedText = new FormattedText(
|
||||||
|
text,
|
||||||
|
CultureInfo.CurrentUICulture,
|
||||||
|
flowDirection,
|
||||||
|
typeface,
|
||||||
|
fontSize, Brushes.Black);
|
||||||
|
#else
|
||||||
|
var formattedText = new FormattedText(
|
||||||
|
text,
|
||||||
|
CultureInfo.CurrentUICulture,
|
||||||
|
flowDirection,
|
||||||
|
typeface,
|
||||||
|
fontSize, Brushes.Black, DpiHelper.DeviceDpiX);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return formattedText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user