I'm trying to stretch the orange grid so that it fills out horizontally, currently it only fills out the length of the textblock that's inside. Why is that?
<ListView ItemsSource="{Binding Users}"
Grid.Column="0">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="50"
Background="Orange"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Rectangle RadiusX="20" RadiusY="20"
Width="30" Height="30">
<Rectangle.Fill>
<SolidColorBrush Color="Orange" />
</Rectangle.Fill>
</Rectangle>
<StackPanel Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Stretch">
<TextBlock Text="{Binding }"
FontWeight="Bold"
HorizontalAlignment="Stretch"/>
</StackPanel>
<Grid.Effect>
<DropShadowEffect Opacity=".1"
BlurRadius="10"
Direction="280"/>
</Grid.Effect>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
This is what it looks like
I forgot to add HorizontalContentAlignment="Stretch" to the ListView.
<ListView ItemsSource="{Binding Users}"
Grid.Column="1"
HorizontalContentAlignment="Stretch">
Related
I've been trying to create control dynamically and so far it is working. But my problem is the layout
<Grid Grid.Row="2" >
<ItemsControl IsTabStop="False" ItemsSource="{Binding ListControls}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120*"/>
<RowDefinition Height="120*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="AN:" Margin="5,5,5,5" FontSize="14" VerticalContentAlignment="Center"/>
<TextBox Grid.Column="1" FontSize="14" VerticalContentAlignment="Center" Margin="5,5,5,5"/>
</Grid>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
With the xaml above. this is the screenshot of the layout
and if i use a xaml like this
<Grid Grid.Row="2" >
<ItemsControl IsTabStop="False" ItemsSource="{Binding ListControls}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Label Content="AN:" Margin="5,5,5,5" FontSize="14" VerticalContentAlignment="Center"/>
<TextBox Width="100" FontSize="14" VerticalContentAlignment="Center" Margin="5,5,5,5"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
But my goal is i want the textbox to expand if the program is maximized.
How can i adjust the xaml code in order to expand the textbox? Thank you
Directly use Grid instead of StackPanel also remove Width="100".
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="AN:" Margin="5,5,5,5" FontSize="14" VerticalContentAlignment="Center"/>
<TextBox Grid.Column="1" FontSize="14" VerticalContentAlignment="Center" Margin="5,5,5,5"/>
</Grid>
I have this DataTemplate that contains a Map
<DataTemplate x:Key="MyMeetingsWithMapSquares">
<Grid Width="350" Height="290" DataContext="{Binding}" >
<StackPanel >
<StackPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0,1" >
<GradientStop Color="#FF0072C6" Offset="0"/>
<GradientStop Color="#FF008FD4" Offset="1"/>
</LinearGradientBrush>
</StackPanel.Background>
<Grid DataContext="{Binding}">
<Grid.RowDefinitions>
<RowDefinition Height="90"/>
<RowDefinition Height="60"/>
<RowDefinition Height="50"/>
<RowDefinition Height="150"/>
</Grid.RowDefinitions>
<Border BorderBrush="#0166a0" BorderThickness="0,0,0,1" Margin="10,0,10,0">
<StackPanel Grid.Row="0">
<Grid DataContext="{Binding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Row="0" Margin="0,16,0,0" Text="{Binding MyMeetingSquareDayNumber}" Width="40" FontFamily="Segoe UI Semibold" FontSize="33" FontWeight="SemiBold" VerticalAlignment="Top"/>
<TextBlock Grid.Row="0" Margin="0,16,0,0" Text="{Binding MyMeetingSquareMonthText}" Width="60" FontFamily="Segoe UI Regular" FontSize="33" FontWeight="Normal" VerticalAlignment="Top"/>
<TextBlock Grid.Row="0" Margin="0,16,0,0" Text="{Binding MyMeetingSquareYearText}" Width="60" FontFamily="Segoe UI Light" FontSize="33" FontWeight="Light" VerticalAlignment="Top" HorizontalAlignment="Left"/>
</StackPanel>
<TextBlock Grid.Row="1" Margin="0,5,0,0" Text="Business meeting" FontFamily="Segoe UI Semibold" FontSize="24" FontWeight="SemiBold" VerticalAlignment="Center"/>
</Grid>
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="{Binding MyMeetingSquareDayHour}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0"/>
</StackPanel>
</Grid>
</StackPanel>
</Border>
<Border Grid.Row="1" BorderBrush="#0166a0" BorderThickness="0,0,0,1" Margin="10,0,10,0">
<StackPanel >
<TextBlock Text="{Binding MyMeetingSquareSummary}" FontFamily="Segoe UI Light" FontSize="16" Margin="0,10,0,10" TextWrapping="Wrap"/>
</StackPanel>
</Border>
<StackPanel Grid.Row="2">
<Border BorderBrush="#0166a0" BorderThickness="0,0,0,1" Margin="10,0,10,0">
<ScrollViewer VerticalScrollBarVisibility="Hidden" VerticalScrollMode="Disabled" HorizontalScrollBarVisibility="Hidden" HorizontalScrollMode="Enabled">
<GridView ItemContainerStyle="{StaticResource GridViewItemStyle2}" ItemsSource="{Binding MyMeetingsSquareUsers}" ItemTemplateSelector="{StaticResource meetingSelector}" Grid.Row="1" Margin="0,10,0,0" SelectionMode="None" HorizontalContentAlignment="Left" VerticalContentAlignment="Bottom">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Vertical" MaximumRowsOrColumns="1"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</ScrollViewer>
</Border>
</StackPanel>
<StackPanel Grid.Row="3" Height="150" DataContext="{Binding}">
<Maps:Map Tag="{Binding MyMeetingSquareLat}" Margin="0,10,0,0" DoubleTappedOverride="Map_DoubleTappedOverride" ShowBreadcrumb="False" Height="150" ShowNavigationBar="False" ShowScaleBar="False" ShowTraffic="False" Width="350" Credentials="AnZKLHgAfKSwa5BAB2Kr-g8KENJBm1US3txxxxxxzCDUAgxhgJZVXyUgRIwM" ViewChanged="Map_ViewChanged" >
<Maps:Map.Center>
<Maps:Location Latitude="{Binding MyMeetingSquareLat}" Longitude="{Binding MyMeetingSquareLng}"/>
</Maps:Map.Center>
</Maps:Map>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</DataTemplate>
Im trying to bind values to its latitude and longitude, but for some reason they are allways 0. i tried binding one of the values to the Map tag and it worked, the tag was 49.597378 but the latitude was 0.
how do i pass the values to the map lat and lng ?
EDIT
so i've changed some things on my code and added a pushpin
<StackPanel Grid.Row="3" Height="150" DataContext="{Binding}">
<Maps:Map Tag="{Binding MyMeetingSquareLat}" DataContext="{Binding}" ZoomLevel="5" Margin="0,10,0,0" DoubleTappedOverride="Map_DoubleTappedOverride" ShowBreadcrumb="False" Height="150" ShowNavigationBar="False" ShowScaleBar="False" ShowTraffic="False" Width="350" Credentials="AnZKLHgAfKSwa5BAB2Kr-g8KENJBmxxxxxxyOCEwbJzCDUAgxhgJZVXyUgRIwM" ViewChanged="Map_ViewChanged" >
<Maps:Map.Center>
<Maps:Location Latitude="{Binding MyMeetingSquareLat}" Longitude="{Binding MyMeetingSquareLng}"/>
</Maps:Map.Center>
<Maps:Map.Children>
<Maps:Pushpin >
<Maps:Pushpin.Background>
<ImageBrush Stretch="Fill" ImageSource="ms-appx:///Assets/Pdf/edit.png"/>
</Maps:Pushpin.Background>
<Maps:MapLayer.Position>
<Maps:Location Latitude="{Binding MyMeetingSquareLat}" Longitude="{Binding MyMeetingSquareLng}" />
</Maps:MapLayer.Position>
</Maps:Pushpin>
</Maps:Map.Children>
</Maps:Map>
</StackPanel>
</Grid>
</StackPanel>
The pushpins appear in the correct position, but the map center continues to go to point 0 0 , it doesnt read the binded values for some reason.
You are binding a string (as you said in the comments) to the Latitude property of Maps:Location. However Maps:Location expects a double for this value.
You need to convert this value into a double with the following code:
Double.Parse(myStringValue);
If the value MyMeetingSquareLat can't be changed to a string itself, then add another property like this, and bind to it instead:
public Double MyMeetingSquareLatDouble
{
get
{
return Double.Parse(this.MyMeetingSquareLat);
}
}
I have the following Question:
I have a Layout with a Grid and ListViews.
These ListViews will always contain 5 Items.
Now these Items should fill the complete Height of the ListView.
So I thought I get the Height of the ListView an then devide it by 5 and set the Height of each Row to the Result.
But the ListView.Height Property returns strange Values.
I listen to the Window SizeChanged Event.
I hope somebody can tell me how to do it, or if there is a better alternative.
<Window x:Class="KalenderDesingTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Kalender" Height="600" Width="800" SizeChanged="Window_SizeChanged">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type ListViewItem}">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border BorderBrush="#5076A7" BorderThickness="1" CornerRadius="4">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#FFFFFF" Offset="0.0"/>
<GradientStop Color="#C0D3EA" Offset="1.0"/>
</LinearGradientBrush>
</Border.Background>
<StackPanel TextElement.FontFamily="Segoe UI"
TextElement.FontSize="12">
<TextBlock FontWeight="Bold" Padding="3,0,0,0" Text="{Binding Path=Name}"/>
<TextBlock Padding="3,0,0,0" Text="{Binding Path=Age}"/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0"
Grid.RowSpan="3" x:Name="NeuerTermin">Neuer Termin</Button>
<Button Grid.Column="2" Grid.Row="0" x:Name="Back">Zurück</Button>
<ComboBox Grid.Column="3" Grid.Row="0" x:Name="Month"></ComboBox>
<Button Grid.Column="4" Grid.Row="0" x:Name="Forward">Vor</Button>
<TextBlock Grid.Column="1" Grid.Row="1" Text="Montag" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="2" Grid.Row="1" Text="Dienstag" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="3" Grid.Row="1" Text="Mittwoch" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="4" Grid.Row="1" Text="Donnerstag" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="5" Grid.Row="1" Text="Freitag" HorizontalAlignment="Center"/>
<StackPanel Orientation="Horizontal" Grid.Column="1"
Grid.Row="2" VerticalAlignment="Stretch">
<CheckBox x:Name="MoV" VerticalAlignment="Center" Margin="0,0,5,0">V</CheckBox>
<CheckBox x:Name="MoN" VerticalAlignment="Center" Margin="0,0,5,0">N</CheckBox>
<CheckBox x:Name="MoT" VerticalAlignment="Center">T</CheckBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Column="2"
Grid.Row="2" VerticalAlignment="Stretch">
<CheckBox x:Name="DiV" VerticalAlignment="Center" Margin="0,0,5,0">V</CheckBox>
<CheckBox x:Name="DiN" VerticalAlignment="Center" Margin="0,0,5,0">N</CheckBox>
<CheckBox x:Name="DiT" VerticalAlignment="Center">T</CheckBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Column="3"
Grid.Row="2" VerticalAlignment="Stretch">
<CheckBox x:Name="MiV" VerticalAlignment="Center" Margin="0,0,5,0">V</CheckBox>
<CheckBox x:Name="MiN" VerticalAlignment="Center" Margin="0,0,5,0">N</CheckBox>
<CheckBox x:Name="MiT" VerticalAlignment="Center">T</CheckBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Column="4"
Grid.Row="2" VerticalAlignment="Stretch">
<CheckBox x:Name="DoV" VerticalAlignment="Center" Margin="0,0,5,0">V</CheckBox>
<CheckBox x:Name="DoN" VerticalAlignment="Center" Margin="0,0,5,0">N</CheckBox>
<CheckBox x:Name="DoT" VerticalAlignment="Center">T</CheckBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Column="5"
Grid.Row="2" VerticalAlignment="Stretch">
<CheckBox x:Name="FrV" VerticalAlignment="Center" Margin="0,0,5,0">V</CheckBox>
<CheckBox x:Name="FrN" VerticalAlignment="Center" Margin="0,0,5,0">N</CheckBox>
<CheckBox x:Name="FrT" VerticalAlignment="Center">T</CheckBox>
</StackPanel>
<ListView Grid.Column="1" Grid.Row="3" x:Name="lvMoV"></ListView>
<ListView Grid.Column="1" Grid.Row="4" x:Name="lvMoN"></ListView>
<ListView Grid.Column="2" Grid.Row="3" x:Name="lvDiV"></ListView>
<ListView Grid.Column="2" Grid.Row="4" x:Name="lvDiN"></ListView>
<ListView Grid.Column="3" Grid.Row="3" x:Name="lvMiV"></ListView>
<ListView Grid.Column="3" Grid.Row="4" x:Name="lvMiN"></ListView>
<ListView Grid.Column="4" Grid.Row="3" x:Name="lvDoV"></ListView>
<ListView Grid.Column="4" Grid.Row="4" x:Name="lvDoN"></ListView>
<ListView Grid.Column="5" Grid.Row="3" x:Name="lvFrV"></ListView>
<ListView Grid.Column="5" Grid.Row="4" x:Name="lvFrN"></ListView>
</Grid>
</Window>
This is my code behind:
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
int wHeight = (int)lvMoN.Height;
}
I would do like this:
int wHeight = (int)lvMoN.ActualHeight;
How would I make mainGrid horizontally stretch to the size of the listbox? I've got the listbox set to stretch and auto width and mainGrid set to stretch and auto but its not stretching to the size of the listbox.
<DataTemplate x:Key="AccountItem">
<Grid Name="mainGrid" ShowGridLines="True">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="#FFFFFFF3"/>
<GradientStop Color="DarkGray" Offset="0.672"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid VerticalAlignment="Top" Grid.Row="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="accountName" TextWrapping="Wrap" Text="{Binding Name}" HorizontalAlignment="Left" Foreground="White"/>
<TextBlock x:Name="accountType" TextWrapping="Wrap" Text="{Binding Type}" Foreground="White" HorizontalAlignment="Right" Grid.Column="1"/>
</Grid>
<Grid VerticalAlignment="Center" Grid.Row="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock TextWrapping="Wrap" Text="Balance:" HorizontalAlignment="Left" Foreground="White"/>
<TextBlock x:Name="accountBalance" TextWrapping="Wrap" Text="{Binding Balance}" HorizontalAlignment="Right" Foreground="White" Grid.Column="1"/>
</Grid>
<Grid VerticalAlignment="Bottom" Grid.Row="2" >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock TextWrapping="Wrap" Text="Available Balance:" HorizontalAlignment="Left" Foreground="White"/>
<TextBlock x:Name="accountAvailableBalance" TextWrapping="Wrap" Text="{Binding AvailableBalance}" HorizontalAlignment="Right" Foreground="White" Grid.Column="1"/>
</Grid>
</Grid>
</DataTemplate>
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="/Assets/background.png"/>
</Grid.Background>
<ListBox x:Name="accountsList" Margin="20,136,20,0" ItemTemplate="{StaticResource AccountItem}" />
</Grid>
Try to set HorizontalContentAlignment to Strecth:
<ListBox x:Name="accountsList" Margin="20,136,20,0" ItemTemplate="{StaticResource AccountItem}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
I have a DataTemplate for my list items which looks like this:
<DataTemplate x:Key="MyDataTemplate">
<Grid Height="60">
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="88"/>
<ColumnDefinition Width="310"/>
<ColumnDefinition Width="72"/>
</Grid.ColumnDefinitions>
<Image MaxHeight="48" MaxWidth="40" Grid.Column="0" VerticalAlignment="Center" Source="{Binding ImageUrl}"/>
<TextBlock Text="{Binding Name}" Grid.Column="1"/>
<ContentPresenter x:Name="AnimatedIndicator" Grid.Column="2" RenderTransformOrigin="0.5, 0.5">
<ContentPresenter.ContentTemplate>
<DataTemplate>
<Image Source="/Assets/Images/arrow.png" CacheMode="BitmapCache" Width="30" Height="30" Stretch="Uniform"/>
</DataTemplate>
</ContentPresenter.ContentTemplate>
<ContentPresenter.RenderTransform>
<RotateTransform x:Name="AnimatedIndicatorRotate" Angle="{Binding IsRotated, Converter={StaticResource IsRotatedToAngleConverter}}"/>
</ContentPresenter.RenderTransform>
</ContentPresenter>
</Grid>
</Grid>
</DataTemplate>
My problem is that the binding in the RotateTransform does not work, and the converter does not get called.
So when I animate the angle with a storyboard, after some scrolling because of the virtualization the angle is reset, and binding to the IsRotated property should fix this, but it does not work.