세로로 WPF 단추에 텍스트를 표시하는 방법을 알고 싶습니다. I가 높은 직사각형 버튼이, 폭 = 38, 높이 = 90 I는
B
U 같은 텍스트
YWPF 세로 텍스트 단추
또는
S
E
L을 표시하는 버튼을하고자
L
누구나 WPF에서 어떻게 달성 할 수 있는지 말해 줄 수 있습니까?
감사
세로로 WPF 단추에 텍스트를 표시하는 방법을 알고 싶습니다. I가 높은 직사각형 버튼이, 폭 = 38, 높이 = 90 I는
B
U 같은 텍스트
YWPF 세로 텍스트 단추
또는
S
E
L을 표시하는 버튼을하고자
L
누구나 WPF에서 어떻게 달성 할 수 있는지 말해 줄 수 있습니까?
감사
당신은 단순히, 그것의 내부 요소의 목록을 작성 그들이 수직 보이게됩니다 ItemsControl에를 사용할 수 있습니다.
<Button>
<ItemsControl ItemsSource="BUY" />
</Button>
당신은
this 질문에이 같은 일을에 대한 자세한 정보를 찾을 수 있습니다
..
string을 'IEnumerable'으로 영리하게 사용합니다. +1은 단순한 대담성을 말하지만 약간의 설명을 사용할 수는 있습니다. – BradleyDotNET
어쩌면이 답변을하는 데 도움이됩니다. 기본적으로 버튼에 추가 된 텍스트를 감싸는 스타일이 필요합니다. 이 답변 밖으로
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>
컨버터의 코드 : 도움 뷰 모델
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";
}
}
}
희망에 대한
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DilbertDownloader
{
public class TextVerticalConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!(value is string)) return value;
var converted = "";
foreach (var character in (string)value)
{
//If the character is a space, add another new line
//so we get a vertical 'space'
if (character == ' ') {
converted += '\n';
continue;
}
//If there's a character before this one, add a newline before our
//current character
if (!string.IsNullOrEmpty(converted))
converted += "\n";
converted += character;
}
return converted;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//Not really worried about this at the moment
throw new NotImplementedException();
}
}
}
그리고 코드
리 사용 neBreak 및 리터럴 LINEBREAK
<Button Width="38" Height="90" Content="B
u
y"/>
<Button Width="38" Height="90">
<TextBlock>
<Run Text="S"/>
<LineBreak/>
<Run Text="E"/>
<LineBreak/>
<Run Text="L"/>
<LineBreak/>
<Run Text="L"/>
<LineBreak/>
</TextBlock>
</Button>
설정 폭과 textwrapping는
<Button Width="38" Height="90">
<TextBlock Text="Buy" Width="8" TextWrapping="Wrap"></TextBlock>
</Button>
당신이 어떤 노력을 만들었을 TextBlock을 하는가? –