Bind the Height of the Listbox inside the StackPanel to StackPanel`s height
Tag : wpf , By : cthulhup
Date : March 29 2020, 07:55 AM
With these it helps I want to bind the Height of the ListBox to the Height of the StackPanel so the ListBox stretches itself Vertically so the green area is not visible anymore. , Simply use a Grid instead of a StackPanel: <Grid x:Name="grid"
Background="Green"
DataContext="{Binding DocumentViewModelList}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox Grid.Row="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" ..... />
<UniformGrid Grid.Row="1"
Rows="1"
HorizontalAlignment="Center"
VerticalAlignment="Bottom">
<Button Content="Delete" />
<Button Content="Add" />
<Button Content="Open" />
</UniformGrid>
</Grid>
|
How to bind Background to the StackPanel
Tag : chash , By : Lucyberad
Date : March 29 2020, 07:55 AM
like below fixes the issue There are two ways to do the above mentioned scenerio 1)We can add Background property to the objects that populates ObservableCollection and using binding in xaml <Grid Width="200" Background="{Binding Background}" />
object.Background = "White"
<TextBlock Text="{Binding Path=alreadyDownload}"
<StackPanel Width="260" Height="80" Background="{Binding RelativeSource={RelativeSource Self}, Path=alreadyDownload, Converter={StaticResource ColorConverter}}">
<TextBlock x:Name ="AAA" Text="{Binding Path=Chapter}" FontSize="10" Foreground="White" d:LayoutOverrides="Width" Margin="5" TextWrapping="Wrap" />
<TextBlock Text="{Binding Path=Name}" Foreground="White" d:LayoutOverrides="Width" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Path=alreadyDownload}" Foreground="#073363" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,18,2,2" FontSize="10" d:LayoutOverrides="Width" TextWrapping="Wrap"/>
</StackPanel>
if (value.Equals("Already Downloaded "))
return Colors.Red;
else
return Colors.White;
if (value.Equals("Already Downloaded "))
return "#FF0000";
else
return "#FFFFFF";
|
Bind list of images to StackPanel
Tag : image , By : Sanoran
Date : March 29 2020, 07:55 AM
I hope this helps . Ok, so the solution of this problem was the use of ContentPresenter combined with a converter. Now my XAML looks like this: <DataGrid name="dataGrid1">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Path=Name}"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Images, Converter={StaticResource ImageCollectionConverter}}"/>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
public class ImageCollectionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
List<MyImage> images = value as List<MyImage>;
if (images != null)
{
StackPanel stack = new StackPanel();
stack.Orientation = Orientation.Horizontal;
foreach (DesignImage img in images)
{
Image image = new Image();
image.Source = img.Image;
stack.Children.Add(image);
}
return stack;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
|
How to bind a list of items to textbox inside stackpanel
Tag : chash , By : rixtertech
Date : March 29 2020, 07:55 AM
around this issue your approach to deal with tags is not correct here, you do not want a text box here, you need a control that can understand what a tag is and how to deal with it. Have a look here and here to understand how to implement this. <ItemsControl ItemsSource="{x:Bind Items}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="PowderBlue" CornerRadius="5" BorderThickness="2" Height="45" Margin="5" >
<TextBlock Text="{Binding}" VerticalAlignment="Center" Margin="5"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
public MainWindow()
{
InitializeComponent();
Items = new[] {"ABC", "DEF"};
this.DataContext = this;
}
public string[] Items
{ get; set; }
|
How to bind StackPanel content with a list of Images
Tag : chash , By : user171752
Date : March 29 2020, 07:55 AM
|