這是一個有點哈克,但我發現,解決辦法是忘記試圖對準直接使用功能區元素對齊控制元件和內RibbonGroup
的第一個挑戰是對齊使用網格中的元素網格本身並沒有在功能區組中正確對齊,但我通過將網格的寬度綁定到功能區組的寬度來解決該問題,因此將在功能區組調整大小時調整網格的寬度。
第二個是對齊標籤,因爲標籤是RibbonTextBox
控件的一部分。解決方案是使用另一個控件來提供文本標籤(Label
或TextBlock
),並將RibbonTextBox.Label
留爲空白。
<RibbonGroup x:Name="PSO2" Header="Data Entry Section" Width="270">
<Grid Width="{Binding ElementName=PSO2, Path=ActualWidth}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="x1_min" Grid.Column="0" Grid.Row="0" />
<RibbonTextBox Label="" SmallImageSource="Images/Document.png" TextBoxWidth="50" Grid.Column="1" Grid.Row="0"/>
<TextBlock Text="x1_max" Grid.Column="0" Grid.Row="1" />
<RibbonTextBox Label="" SmallImageSource="Images/Document.png" TextBoxWidth="50" Grid.Column="1" Grid.Row="1"/>
<TextBlock Text="x2_min" Grid.Column="0" Grid.Row="2" />
<RibbonTextBox Label="" SmallImageSource="Images/Document.png" TextBoxWidth="50" Grid.Column="1" Grid.Row="2"/>
<TextBlock Text="x2_max" Grid.Column="2" Grid.Row="0" />
<RibbonTextBox Label="" SmallImageSource="Images/Document.png" TextBoxWidth="50" Grid.Column="3" Grid.Row="0"/>
<TextBlock Text="Iterations" Grid.Column="2" Grid.Row="1" />
<RibbonTextBox Label="" SmallImageSource="Images/Document.png" TextBoxWidth="50" Grid.Column="3" Grid.Row="1"/>
</Grid>
</RibbonGroup>
並使用此,你結束了一個RibbonGroup看起來像
最大的限制是RibbonTextBox的形象會在標籤和文本框之間錯位。爲了克服這個問題,你必須添加一個額外的列集,並把圖標放在那裏,而不是使用RibbonTextBox.SmallImageSource
在這裏發佈x1 max的xaml標記 – Sivasubramanian
@Sivasubramanian發佈。我應該發佈完整的XAML嗎? –
嗨嘗試刪除您的XAML中的標記SmallImageSource,並讓我是否可以正確對齊? – Sivasubramanian