I would like to get the width and height of both the borders from code and change them programmatically. I have a button that should change the size of both of them but I don't know how to get them from my class. How can I do it? The size of both is always the same
<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>
CodePudding user response:
Updated:
xaml:
<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>
code:
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 });
}