我想直接在WPF. 我會這樣做,xaml代碼看起來像這樣:
<Button Grid.Row="0" HorizontalAlignment="Left" Style="{StaticResource btnRaw}" Background="Transparent" BorderThickness="0" Height="17" Width="17" ToolTip="Tooltip" Click="DeleteLastEntry">
<Grid>
<TextBlock Grid.Column="0" Foreground="{StaticResource brushLayerstackCoherent}" VerticalAlignment="Center" HorizontalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontSize="14.8" Text="" />
<TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" FontFamily="Segoe MDL2 Assets" FontSize="9" FontWeight="Bold" Text="" />
</Grid>
</Button>
但是xaml,我不想在C#. 我可以創建一個button這樣的
Button myButton = new Button();
myButton.HorizontalAlignment = HorizontalAlignment.Left;
...
但是如何在按鈕內添加網格?Children中不存在通過 -property 進行的訪問myButton。
uj5u.com熱心網友回復:
var button = new Button();
var textBlock1 = new TextBlock();
var textBlock2 = new TextBlock();
var grid = new Grid();
grid.Children.Add(textBlock1);
grid.Children.Add(textBlock2);
button.Content = grid;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/443432.html
