Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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垂直文本输入按钮_C#_Wpf - Fatal编程技术网

C# WPF垂直文本输入按钮

C# WPF垂直文本输入按钮,c#,wpf,C#,Wpf,我想知道如何在WPF按钮中垂直显示文本。我有一个高高的矩形按钮,宽度=38,高度=90。我希望按钮将文本显示为 B U Y 或 S E L L 谁能告诉我如何在WPF中实现这一点 谢谢,您可以简单地使用ItemsControl,它将在其中创建元素列表,使它们看起来垂直 <Button> <ItemsControl ItemsSource="BUY" /> </Button> 您可以在问题中找到有关执行类似操作的更多信息。您可以简单地使用Items

我想知道如何在WPF按钮中垂直显示文本。我有一个高高的矩形按钮,宽度=38,高度=90。我希望按钮将文本显示为
B
U
Y

S
E
L
L

谁能告诉我如何在WPF中实现这一点


谢谢,您可以简单地使用ItemsControl,它将在其中创建元素列表,使它们看起来垂直

<Button>
    <ItemsControl ItemsSource="BUY" />
</Button>


您可以在问题中找到有关执行类似操作的更多信息。

您可以简单地使用ItemsControl,它将在其中创建一个元素列表,使它们看起来垂直

<Button>
    <ItemsControl ItemsSource="BUY" />
</Button>


你可以在问题中找到更多关于做类似事情的信息。

也许这个答案对你有帮助。 基本上,您需要一个样式来包装添加到按钮中的文本

看看这个答案:
也许这个答案对你有帮助。 基本上,您需要一个样式来包装添加到按钮中的文本

看看这个答案:
带有ItemsControl的答案听起来很完美,但如果您不想这样做,可以创建一个转换器,在文本的每个字符之间添加“\n”

页面的XAML:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DilbertDownloader" x:Class="DilbertDownloader.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <local:TextVerticalConverter x:Key="TextVerticalConverter"/>
    </Window.Resources>
    <Window.DataContext>
        <local:ViewModel/>
    </Window.DataContext>
    <Grid>
        <Button Content="{Binding ButtonText, Converter={StaticResource TextVerticalConverter}}" HorizontalAlignment="Left" Margin="270,156,0,0" VerticalAlignment="Top" Width="75"/>
    </Grid>
</Window>
以及ViewModel的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DilbertDownloader
{
    public class ViewModel
    {
        public string ButtonText { get; set; }

        public ViewModel()
        {
            ButtonText = "BUY";
        }
    }
}

希望这有帮助

带有ItemsControl的答案听起来很完美,但如果您不想这样做,可以创建一个转换器,在文本的每个字符之间添加“\n”

页面的XAML:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DilbertDownloader" x:Class="DilbertDownloader.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <local:TextVerticalConverter x:Key="TextVerticalConverter"/>
    </Window.Resources>
    <Window.DataContext>
        <local:ViewModel/>
    </Window.DataContext>
    <Grid>
        <Button Content="{Binding ButtonText, Converter={StaticResource TextVerticalConverter}}" HorizontalAlignment="Left" Margin="270,156,0,0" VerticalAlignment="Top" Width="75"/>
    </Grid>
</Window>
以及ViewModel的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DilbertDownloader
{
    public class ViewModel
    {
        public string ButtonText { get; set; }

        public ViewModel()
        {
            ButtonText = "BUY";
        }
    }
}

希望这对使用LineBreak和Literal LineBreak有所帮助

<Button Width="38" Height="90" Content="B&#x0a;u&#x0a;y"/>



将宽度和换行设置为textblock

<Button Width="38" Height="90">
    <TextBlock Text="Buy" Width="8" TextWrapping="Wrap"></TextBlock>
</Button>

使用换行符和文字换行符

<Button Width="38" Height="90" Content="B&#x0a;u&#x0a;y"/>



将宽度和换行设置为textblock

<Button Width="38" Height="90">
    <TextBlock Text="Buy" Width="8" TextWrapping="Wrap"></TextBlock>
</Button>


你做了什么?你做了什么?巧妙地使用字符串作为
IEnumerable
+1纯粹是为了大胆,尽管它可能需要一些解释。巧妙地使用字符串作为
IEnumerable
+1纯粹是为了大胆,尽管这需要一些解释。