Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当我输入多行文本时,Wpf Textblock宽度会发生变化_C#_Wpf_Scale_Textblock - Fatal编程技术网

C# 当我输入多行文本时,Wpf Textblock宽度会发生变化

C# 当我输入多行文本时,Wpf Textblock宽度会发生变化,c#,wpf,scale,textblock,C#,Wpf,Scale,Textblock,你好,我试图让我的文字在按钮上使用所有可用的空间,并保持可伸缩性 这是我当前的代码 <Button x:Name="ButtonTest" Grid.Column="5" Margin="5" Style="{DynamicResource FunctionButton}"> <Button.Content> <Viewbox x:Name="ViewTest"> <TextBlock Width="{Bi

你好,我试图让我的文字在按钮上使用所有可用的空间,并保持可伸缩性

这是我当前的代码

<Button x:Name="ButtonTest" Grid.Column="5" Margin="5" Style="{DynamicResource FunctionButton}">
    <Button.Content>
        <Viewbox x:Name="ViewTest">
            <TextBlock Width="{Binding Path=ActualWidth, ElementName=ButtonTest}" 
                       TextWrapping="Wrap"  Text="Test test test test test test test test test test test test test test test test test test test"></TextBlock>
        </Viewbox>
    </Button.Content>
</Button>

用我的代码,如果我输入足够的文本,使多行的宽度减少

我可以手动设置textblock的宽度并生成它。那么,当我输入多行时,为什么绑定不起作用呢

使用的样式

<Style x:Key="FunctionButtonBase" TargetType="{x:Type Button}">
    <Setter Property="FontWeight" Value="SemiBold"></Setter>
    <Setter Property="FontSize" Value="15"></Setter>
    <Setter Property="Foreground" Value="{DynamicResource NormalFontBrush}"></Setter>
</Style>

<Style x:Key="FunctionButton" TargetType="{x:Type Button}" BasedOn="{StaticResource FunctionButtonBase}">
    <Setter Property="Background" Value="{DynamicResource NormalButtonBrush}"></Setter>
</Style>


也许你应该设置ViewBox和/或TextBlock的水平对齐和/或水平内容对齐?水平对齐与拉伸没有区别,我不知道如何设置水平内容对齐我必须阅读这篇文章:)@Dennis:啊,我没有想到这种风格。我可以玩这个。我用style@Dennis:您确定它在没有样式的情况下有效吗?我来不了work@Dendei它不适用于
ViewBox
,它将使用
TextBlock
实际矩形并将其缩放(向上或向下)以适合可用矩形。您需要的是某种
FontSize
自定义转换器,如果文本不适合,它会降低文本大小