How to change the Datagrid selcted row color and data grid Header Font in UWP xaml - xaml

i want to change the data grid selected row color and height of the data grid columns in uwp xaml
i am using xamarin forms.
after installing the packages from NuGet. i am able to use the data grid. now problem is how to change the data grid column/row height and selected row color in uwp
my data grid xaml code : =
<controls:DataGrid AutoGenerateColumns="False" CanUserResizeColumns="False" IsReadOnly="True" Margin="31,21,103,483" Name="UserListView" VerticalScrollBarVisibility="Auto" UseLayoutRounding="True" HorizontalScrollBarVisibility="Auto" TabIndex="4" FontSize="14" Background="White"
HeadersVisibility="Column" SelectedIndex="0" HorizontalGridLinesBrush="#E1E1E1" IsTabStop="True" RenderTransformOrigin="0.504,0.739" Grid.Row="2" BorderBrush="#E1E1E1" BorderThickness="1" Grid.Column="2" Grid.ColumnSpan="7" >
<controls:DataGrid.Columns >
<controls:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" Width="50" x:Name="userCheckBox" >
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<CheckBox Foreground="#444444" Height="10" Width="10" Margin="15,10,0,10" x:Name="IndvCheckBox" DataContext="{Binding userId}" Unchecked="UserUnchecked" Checked="UserChecked" UseLayoutRounding="True">
</CheckBox>
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" Header="Name" Width="380" >
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<TextBlock Margin="10,20,0,10" x:Name="NameTextBox" Foreground="#444444" FontSize="12" FontFamily="Montserrat" >
<Run Text="{Binding userPrefix}" />
<Run Text="{Binding userFirstName}" />
<Run Text="{Binding userLastName}" />
</TextBlock>
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" Header="Email" Width="380" >
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<TextBlock Margin="10,20,0,10" Text="{Binding userEmail}" x:Name="NameTextBox" Foreground="#444444" FontSize="12" FontFamily="Montserrat" />
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" Header="Phone" Width="250" >
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<TextBlock FontSize="12" Margin="10,20,0,10" Text="{Binding userPhone}" Foreground="#444444" FontFamily="Montserrat"/>
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTemplateColumn Tag="Col" Header="Update" Width="*">
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<Image HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,20,0,10" Height="15" DataContext="{Binding userId}" Width="15" Source="Images/Edit.png" Tapped="GridUpdateBtnClick" />
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
</controls:DataGrid.Columns>
</controls:DataGrid>

How to change the Datagrid selcted row color
There is ActiveRowColor property in DataGrid control that used to manage Row selected color. For more please refer this.
<dg:DataGrid ActiveRowColor="Red"/>
and data grid Header Font in UWP xaml
You could use the following code to manage the header font size.
<dg:DataGrid.HeaderFontSize>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Tablet>15</OnIdiom.Tablet>
<OnIdiom.Phone>12</OnIdiom.Phone>
</OnIdiom>
</dg:DataGrid.HeaderFontSize>
Unfortunately, DataGrid does not provide FontFamily property for Header. So you need set HeaderLabelStyle like the following.
<dg:DataGrid.HeaderLabelStyle>
<Style TargetType="Label">
<Setter Property="FontFamily" Value="SimSun"></Setter>
</Style>
</dg:DataGrid.HeaderLabelStyle>

Related

How do I change Textbox Header color on hover?

I have the following:
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontSize="12" Header="Name" >
<TextBox.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Red" />
</DataTemplate>
</TextBox.HeaderTemplate>
Is there a way through the DataTemplate or Xaml behaviors to change the Foreground?
You can use XamlBehaviors.
Add Nuget Microsoft.Xaml.Behaviors.Uwp.Managed and references in Xaml.
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
Handle PointerEntered and PointerExited event on TextBlock.
<TextBox HorizontalAlignment="Stretch" VerticalAlignment="Stretch" FontSize="12" Header="Name" >
<TextBox.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Red">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="PointerEntered">
<Core:ChangePropertyAction PropertyName="Foreground">
<Core:ChangePropertyAction.Value>
<SolidColorBrush Color="Blue" />
</Core:ChangePropertyAction.Value>
</Core:ChangePropertyAction>
</Core:EventTriggerBehavior>
<Core:EventTriggerBehavior EventName="PointerExited">
<Core:ChangePropertyAction PropertyName="Foreground">
<Core:ChangePropertyAction.Value>
<SolidColorBrush Color="Red" />
</Core:ChangePropertyAction.Value>
</Core:ChangePropertyAction>
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBlock>
</DataTemplate>
</TextBox.HeaderTemplate>
</TextBox>

Windows Phone 8 xaml textblock binding format

I would like to format a textblock which is bound to a value, to show "R" before the actual value, is this possible, cause I cannot directly change the value?
Thank you
<ListBox x:Name="lstbundleListbox"
Foreground="White"
Height="320"
HorizontalAlignment="Center">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment"
Value="Center" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding name}"
TextWrapping="Wrap"
HorizontalAlignment="Center" />
<TextBlock Text="{Binding cost}"
TextWrapping="Wrap"
HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ListBox>
So I basically want the textblock to show R(cost)
use Run
<TextBlock>
<Run Text="R" />
<Run Text="{Binding cost}" />
</TextBlock>
or use StringFormat
<TextBlock Text="{Binding cost, StringFormat=R{0}}" />
i think this can be done by
<StackPanel Orientation Horizontal>
<TextBlock Text="R(" />
<TextBlock Text="{Binding cost}"/>
<TextBlock Text=")" />
</StackPanel>
distance between them can be set by setting padding of the textblocks...

ListViewItem won't stretch to the width of a ListView

I'm currently designing a windows 8 store app using XAML but I have a minor sizing issue. I have a ListView with a DataTemple.
The code for my ListView & DataTemplate are below:
<ListView x:Name="listPageItems"
Grid.Row="1"
SelectionMode="Extended"
IsSwipeEnabled="False"
ItemsSource="{Binding Mode=OneWay, Source={StaticResource items}}"
ItemTemplate="{StaticResource NavigationItemTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Visible">
</ListView>
<DataTemplate x:Key="NavigationItemTemplate">
<Grid Height="75">
<Grid.RowDefinitions>
<RowDefinition Height="1.6*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Fill="White" />
<Rectangle Fill="{StaticResource SSEGreenBrush}"
Grid.Row="1" />
<Border BorderThickness="2"
BorderBrush="{StaticResource SSEGreenBrush}"
Grid.RowSpan="2" />
<TextBlock x:Name="textTitle"
Text="{Binding ClientName}"
Style="{StaticResource TitleTextStyle}"
Foreground="{StaticResource SSEBlueBrush}"
Margin="10,5,5,5" />
<StackPanel Orientation="Horizontal"
Grid.Row="1"
HorizontalAlignment="Stretch">
<TextBlock Text="Last Edit :"
Style="{StaticResource SubtitleTextStyle}"
Foreground="{StaticResource SSEBlueBrush}"
Margin="3,0,0,3"
VerticalAlignment="Center" />
<TextBlock Text="SurveyDate"
Style="{StaticResource SubtitleTextStyle}"
Foreground="{StaticResource SSEBlueBrush}"
Margin="3,0,0,3"
VerticalAlignment="Center" />
</StackPanel>
</Grid>
</DataTemplate>
The listview is within a grid column with a fixed width of 240.
When the view is displayed the ListViewItems don't stretch to the width of the ListView. I've tried setting numerous properties including the HorizontalContentAlignment but I can't seem to get the ListViewItem to stretch!
Can anybody help?
I'm using Visual studio 2012, C# 4.5 and developing a Windows store app.
Try adding the following to your ListView definition
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
The easiest thing to do is just adding HorizontalContentAlignment="Stretch" to the ListView. There normally is no need for anything more.

ItemsGroups in my GridView don't wrap and are located out of the screen

I just implemented a GridView with groups feature. I have a list of TVshows's episodes which are grouped by diffusion date.
When I have more than 3 episodes by date, I want to have my items wrapped and go next to the group title, at this time, the next items are going outside of the screen, and it not what I wanted.
As you can see, there is other episodes under the dupplicated one for each day, I want them to go next to the others, not under.
Here is my XAML code, thanks :)
<GridView Margin="70,0,0,40" ItemsSource="{Binding Source={StaticResource cvsActivities}}">
<GridView.Template>
<ControlTemplate>
<ItemsPresenter />
</ControlTemplate>
</GridView.Template>
<GridView.ItemContainerTransitions>
<TransitionCollection>
<EntranceThemeTransition IsStaggeringEnabled="True" />
<RepositionThemeTransition />
<AddDeleteThemeTransition />
</TransitionCollection>
</GridView.ItemContainerTransitions>
<GridView.ItemTemplate>
<DataTemplate>
<Grid>
<StackPanel Orientation="Vertical">
<Grid Name="grid_image">
<Image Width="280" Height="200" VerticalAlignment="Center" Stretch="UniformToFill" Source="Assets/no_image.png" />
<Image Width="280" Height="200" VerticalAlignment="Center" Stretch="UniformToFill" Source="{Binding saison.serie.poster}" />
</Grid>
<Image Source="Assets/Ban-1hh.png" Width="280" Height="59" Margin="0,-19,0,0"/>
<Grid Margin="0,-40,0,0" Height="40">
<StackPanel HorizontalAlignment="Left" Orientation="Vertical" VerticalAlignment="Center" Margin="0,-7,0,0">
<TextBlock HorizontalAlignment="Left" Margin="5,0,0,0" Width="190" TextTrimming="WordEllipsis" Foreground="White" FontSize="20" Text="{Binding saison.serie.nom}" />
<TextBlock HorizontalAlignment="Left" Margin="5,-5,0,0" Width="190" TextTrimming="WordEllipsis" Foreground="White" FontSize="13" Text="{Binding date}" />
</StackPanel>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Vertical" Margin="0,-5,5,0">
<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
<TextBlock Foreground="#f0ec45" FontSize="14" Text="{Binding saison.number}" />
<TextBlock Foreground="#f0ec45" FontSize="14" Margin="5,0,0,0" Text="Saison " />
</StackPanel>
<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft" Margin="0,-5,0,0">
<TextBlock Foreground="#f0ec45" FontSize="14" Text="{Binding ep_number}" />
<TextBlock Foreground="#f0ec45" FontSize="14" Margin="5,0,0,0" Text="Episode " />
</StackPanel>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Background="LightGray" >
<TextBlock Text="{Binding Key, Converter={StaticResource StringFormatConverter}, ConverterParameter='{}{0:dddd dd MMM yy}'}" Foreground="Black" Margin="10"
Style="{StaticResource PageSubheaderTextStyle}" />
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</GridView.GroupStyle>
</GridView>
Add a ItemsPanelTemplate (if you take a look at the default GridApp and the GroupedItemsPage.xaml, you'll see this is how they do it).
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0" />
</ItemsPanelTemplate>
</GroupStyle.Panel>
If you want the 3rd element in a column to leak over the bottom, then you can set a negative bottom margin on the GridView itself.
You virtually erased the GridView control template, so no wonder it doesn't work. Remove the following part and things might get back to normal:
<GridView.Template>
<ControlTemplate>
<ItemsPresenter />
</ControlTemplate>
</GridView.Template>
If there is something you want changed in the default template - change that specific thing. The default template has a horizontal ScrollViewer which limits vertical space use by the WrapGrid that is used for its ItemsPanelTemplate and allows items to wrap to next column, while also allowing to scroll horizontally to see all items.

ScrollViewer with multiple datagrids in silverlight

I have 3 datagrid that in a stackpanel and grid that I need to add in a scroll viewer too. When I try to add the scroll viewer to grid or stack panel nothing happens. When I surround the entire stackpanel and grid with a scroll viewer it works but it put the scroll bar to the side of the page separated from the datagrids. What I need is the grid/stackpanel to scroll all three grids together (I don’t want each data grid to scroll; I need them to stay grouped together). Below is my current code. Thank!!
<StackPanel Margin="10,162,0,50" HorizontalAlignment="Left" Width="365">
<Grid>
<Rectangle Fill="{StaticResource BaseColor}"
Stroke="Gray"
RadiusX="10"
RadiusY="10"
Margin="0,0,0,0" />
<StackPanel x:Name="IdentifyResultsStackPanel"
Margin="15,10,15,10"
Visibility="Collapsed">
<TextBlock Text="ELEMENTARY SCHOOL ATTENDANCE AREA:"
Foreground="White"
FontSize="14"
FontStyle="Italic"
Margin="0,0,0,5" />
<slData:DataGrid x:Name="IdentifyDetailsDataGrid"
AutoGenerateColumns="False"
LoadingRow="IdentifyDetailsDataGrid_LoadingRow"
HeadersVisibility="None" >
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
<TextBlock Text="MIDDLE SCHOOL ATTENDANCE AREA:"
Foreground="White"
FontSize="14"
FontStyle="Italic"
Margin="0,0,0,5" />
<slData:DataGrid x:Name="IdentifyDetailsDataGrid2"
AutoGenerateColumns="False"
LoadingRow="IdentifyDetailsDataGrid_LoadingRow"
HeadersVisibility="None" >
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
<TextBlock Text="HIGH SCHOOL ATTENDANCE AREA:"
Foreground="White"
FontSize="14"
FontStyle="Italic"
Margin="0,0,0,5" />
<slData:DataGrid x:Name="IdentifyDetailsDataGrid3"
AutoGenerateColumns="False"
LoadingRow="IdentifyDetailsDataGrid_LoadingRow"
HeadersVisibility="None" >
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
</StackPanel>
</Grid>
</StackPanel>
The stackpanel was the issue. The following link helped me with the problem:
How to add a ScrollBar to a StackPanel in Silverlight?