我想右對齊中顯示的垂直取向StackPanel
內容,我試過HorizontalAlignment="Right"
在StackPanel
本身和ListBox's
DataTemplete
控制(在這種情況下TextBox
,但在現實中我有一個UserControl
在真正的應用程序)垂直方向的StackPanel中的右對齊內容
這裏是目前的結果......我希望每個TextBox
的右邊緣到右對齊...
這裏是XAML,很簡單...
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:WpfApplication2="clr-namespace:WpfApplication2"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance WpfApplication2:Model, IsDesignTimeCreatable=True}">
<ListBox ItemsSource="{Binding Numbers}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Mode=OneWay}" BorderBrush="Black" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Window>
,這裏是我使用的是測試此使用ListBox.ItemContainerStyle
設置HorizontalContentAlignment
模型...
using System;
using System.Collections.Generic;
using System.Linq;
namespace WpfApplication2
{
public class Model
{
[ThreadStatic]
static IDictionary<int, string> dict;
public string[] Numbers
{
get { return dict.OrderBy(x => x.Key).Select(x => x.Value).ToArray(); }
}
public Model()
{
if (dict != null) return;
dict = new Dictionary<int, string>
{
{1, "one"},
{2, "two"},
{3, "three"},
{4, "four"},
{5, "five"},
{6, "six"},
{7, "seven"},
{8, "eight"},
{9, "nine"},
{10, "ten"},
{11, "eleven"},
{12, "twelve"},
{13, "thirteen"},
{14, "fourteen"},
{15, "fifteen"},
{16, "sixteen"},
{17, "seventeen"},
{18, "eighteen"},
{19, "nineteen"},
{20, "twenty"},
{30, "thirty"},
{40, "forty"},
{50, "fifty"},
{60, "sixty"},
{70, "seventy"},
{80, "eighty"},
{90, "ninety"},
{100, "one hundred"},
{200, "two hundred"},
{300, "three hundred"},
{400, "four hundred"},
{500, "five hundred"},
{600, "six hundred"},
{700, "seven hundred"},
{800, "eight hundred"},
{900, "nine hundred"},
{1000, "one thousand"},
};
for (var number = 1; number <= 1000; number++)
{
if (dict.ContainsKey(number)) continue;
var divisor = number < 100 ? 10 : 100;
var separator = divisor == 100 ? " and " : "-";
var key = (number/divisor) * divisor;
var mod = number % divisor;
dict.Add(number, dict[key] + separator + dict[mod]);
}
}
}
}
不建議,物品的選擇將會變淡,因爲物品不再跨越整個寬度(同樣,如果您不需要選擇首先應該使用ItemsControl)。 – 2012-01-05 20:28:02
啊好吧,我看到你的更新答案,這更有意義。謝謝!順便說一句,你一直在幫助我很多我的WPF問題,謝謝你! – 2012-01-05 20:40:08
我有嗎?很高興能有幫助:) – 2012-01-05 20:40:54