ListViewItem does not Stretch - xaml

I have a probleme with the ListViewItem, I define the style like this:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Background" Value="Red"></Setter>
</Style>
</ListView.ItemContainerStyle>
And the result is:
How can I do to stretch ListViewItems ?
Thanks a lot

The problem is not the ItemContainerStyle but the control that I put into the ListView.
The border doest not fit ListViewItem, to solve the problem I set the width to 280 px (320 - 20 * 2, Snapped ViewState)

Related

XAML DataGrid triggering style from other elements

(Note: The Snipping Tool has hidden the mouse cursor hovering over Amelia Earhart in this screen grab.)
When the mouse is RowHeader.IsMouseOver=True then the style is triggered and in this example the font is set to Bold and Italic and the colours change.
Problem: I want to call the same trigger when I Click or Mouseover on any DataGridCell in the row. So if I click on the cell "Hello World" then the RowHeader "Amelia Earhart" is formatted.
<DataGrid.RowHeaderStyle>
<Style TargetType="DataGridRowHeader">
<Setter Property="Width" Value="25"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<!-- I want to trigger this IsMouseOver from DataGridCell.IsMouseOver -->
<Label Content="{Binding [0]}" FontSize="10" Margin="0" >
<Label.Style>
<Style x:Name="sOne" TargetType="Label">
<Setter Property="Foreground" Value="WhiteSmoke"/>
<Setter Property="Background" Value="CadetBlue"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="Cyan"/>
<Setter Property="Background" Value="Navy"/>
</Trigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.RowHeaderStyle>

change barcolor Flyout xamarin xaml

somebody knows how to change the bar color, that I point out in the image
bar flyout
If you want to change the background color of Navigation Bar in shell , we could set the style of Shell navigation bar in Resource Dictionary .
<Shell.Resources>
<ResourceDictionary>
<Color x:Key="NavigationPrimary">#2196F3</Color>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="Red" /> // set navigation bar color here
<Setter Property="Shell.ForegroundColor" Value="Blue" />
<Setter Property="Shell.TitleColor" Value="Blue" />
<Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource NavigationPrimary}" />
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
</Style>
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
</ResourceDictionary>
</Shell.Resources>
For NavigationPage (I assume your detail page is composed of a NavigationPage and inside your HomePage or CurrentNavigatedPageFromMenu, here is a simple style :
<Style x:Key="NavigationPageStyle" TargetType="NavigationPage">
<Setter Property="BarBackgroundColor" Value="Red" />
<Setter Property="BarTextColor" Value="White" />
</Style>
<Style BasedOn="{StaticResource NavigationPageStyle}" TargetType="NavigationPage" />
I separate them to allow to reuse the style on other Navigation page control I've extended.
In code behind, in the constructor of your page (can be usefull to provide a different color depend on the page you are, exemple : red for error page, green for parameter, blue for others).
((NavigationPage)Application.Current.MainPage).BarBackgroundColor = Color.Red;
((NavigationPage)Application.Current.MainPage).BarTextColor = Color.White;
You can find some usefull tips [Xamarin Forum too][1].

ControlTemplate Trigger

<Style TargetType="{x:Type TextBox}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="MinWidth" Value="120" />
<Setter Property="MinHeight" Value="25" />
<Setter Property="AllowDrop" Value="true" />
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border Name="Border" CornerRadius="6" Padding="2" BorderBrush="Black" BorderThickness="2,1">
<ScrollViewer Margin="0" x:Name="PART_ContentHost" />
</Border>
<ControlTemplate.Triggers>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The code above is currently what I have for my text box. What do I put in the ControlTemplate.Trigger in order for my border to change from its color black to Blue or increase the Border size when it is clicked on. I have tried a few things without any luck. This includes style.Triggers and events. Please post the code that goes between the ControlTemplate.Trigger.
This assumes you want to border to be changed when you have it focused, since clicking a textbox focuses it. There is no OnClick property available, this changes the border of a textbox once you have it focused.
<Trigger Property="IsKeyboardFocusWithin"
Value="True">
<Setter Property="BorderBrush"
TargetName="Border"
Value="Blue"/>
</Trigger>
Edit:
To simply remove focus, add the following MouseDown event handler to your Window or Page:
MouseDown="Window_MouseDown"
And in your code behind:
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
Keyboard.ClearFocus();
}
This will correctly remove focus from your TextBox and thus unset the trigger to have a black bar again.

Set TextBlock's Foreground in the Style

Is it possible to set Foreground property from the Style? Looking like it has no effect.
<Style x:Key="MyPageNameStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" />
<Setter Property="Margin" Value="0,12,0,0"/>
<Setter Property="Foreground" Value="Green"/>
</Style>
It's simple be sure you bind it to a static resource
<Grid.Resources>
<Style x:Key="MyPageNameStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" />
<Setter Property="Margin" Value="0,12,0,0"/>
<Setter Property="Foreground" Value="Green"/>
</Style>
</Grid.Resources>
<TextBlock Style="{StaticResource MyPageNameStyle}" Text="WP8 Demodccxzcxzczsczczxcxzczczczcz" Margin="9,-7,0,0" />
Youll be able to see the effect in the xaml designer only

Change the disabled color of a button in XAML Windows 8

I want to be able to change the background color of a button in XAML when it's disabled but I don't know what to override.
Anybody know what I need to do?
I'm create a Windows 8 store app using XAML and C# 4.5.
My current button style is as follows:
<Style x:Key="MySaveButtonStyle"
TargetType="ButtonBase">
<Setter Property="FontFamily"
Value="Segoe UI Symbol" />
<Setter Property="FontSize"
Value="36" />
<Setter Property="Content"
Value="" />
<Setter Property="Height"
Value="70" />
<Setter Property="Width"
Value="80" />
<Setter Property="BorderBrush"
Value="White" />
<Setter Property="Foreground"
Value="{StaticResource ButtonForegroudBrush}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="Background"
Value="White" />
</Style>
Thanks is advance.
You have to override the Default ControlTemplate of the Button.
To do this: Right Click the button in Designer View - Edit Template - Edit a Copy
then Visual Studio creates the default Template for you.
In the Template Code there is a VisualStateManager Section with groups and states.
And one of them is
<VisualState x:Name="Disabled">
//Change to your demands
</VisualState>
Here you can change it to anything what you want to do when a control is Disabled.