我想從代碼中獲取兩個邊框的寬度和高度,并以編程方式更改它們。我有一個按鈕可以改變它們的大小,但我不知道如何從我的課堂上得到它們。我該怎么做?兩者的大小始終相同
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" x:Name="games_list" MouseDoubleClick="Games_list_MouseDoubleClick" Background="{StaticResource DefaultBackgroundColor}" Padding="10" BorderBrush="{x:Null}" Foreground="{x:Null}" SelectionChanged="Games_list_SelectionChanged" KeyDown="Games_list_KeyDown" MouseEnter="Games_list_MouseEnter" MouseLeave="Games_list_MouseLeave" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Margin="10" Width="150" Height="225" Background="{StaticResource DetailsColor}">
<StackPanel>
<Border Width="150" Height="225">
<DockPanel>
<Image Source="/icons/delete.png" Width="24" Height="24" HorizontalAlignment="Left" Margin="2" VerticalAlignment="Top" MouseLeftButtonUp="Delete_MouseLeftButtonUp" >
<Image.Effect>
<DropShadowEffect/>
</Image.Effect>
</Image>
<Image Source="/icons/info.png" Width="24" Height="24" HorizontalAlignment="Right" Margin="2" VerticalAlignment="Top" MouseLeftButtonUp="Info_MouseLeftButtonUp" >
<Image.Effect>
<DropShadowEffect/>
</Image.Effect>
</Image>
</DockPanel>
<Border.Background>
<ImageBrush ImageSource="{Binding Image_path}"/>
</Border.Background>
</Border>
<Rectangle Fill="#4C000000" Margin="0,-20,0,10" Height="20"/>
<TextBlock Text="{Binding Name}" Foreground="White" FontSize="16" TextAlignment="Center" Margin="0,-32,0,44" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ListBox>
uj5u.com熱心網友回復:
你只需要設定一個
更新:
xml:
<Grid Loaded="Grid_Loaded">
<StackPanel Margin="30,40,37,81">
<Border Name="border1" BorderBrush="Black" Margin="5" Loaded="Border_Loaded">
<DockPanel Background="Black">
</DockPanel>
</Border>
</StackPanel>
</Grid>
代碼:
private void Border_Loaded(object sender, RoutedEventArgs e)
{
int c = 500;
int d = 300;
this.border1.SetBinding(Border.HeightProperty, new Binding(".") { Source = c });
this.border1.SetBinding(Border.WidthProperty, new Binding(".") { Source = d });
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/490000.html
