I am new to window phone 8 programming. I watched Channel 9's tutorial called Windows Phone 8 Development for Absolute Beginners, and now I am learning to write some simple code.
Could anyone explain the relationship between the "Style" and the "Grid.Resources" in the sample code below? I though that an inner tag, ie. Style, is a property of it's outer tag, ie. Grid. But it doesn't make sense here since the outer tag, Grid.Resource, is actually a property.
<Grid.Resources>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="Gold" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="Background" Value="Gray" />
<Setter Property="Padding" Value="5" />
</Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Black" />
</Style>
</Grid.Resources>
Any help would be appreciated.
TargetType refers the System.Windows.Controls.Border MSDN which is a class
Property refers to the property of the Border class.
In other words Style can only be based on a class, but that class can be a Property in other class like so:
ListView->View(GridView)
And your Style
<Style x:Key="sampleStyle" x:TargetType="GridView">
<Setter Property="Background" Value="Red"/>
</Setter>
Related
I snooped the desired property and I can change it in real-time:
But I don't know what exactly to set in the code.
When I edit the XAML like this:
<dock:DockingManager x:Name="dockManager" ...>
...
<dock:DockingManager.AnchorablePaneControlStyle>
<Style TargetType="{x:Type dock:LayoutAnchorablePaneControl}">
<Setter Property="BorderBrush" Value="DarkRed"/>
</Style>
</dock:DockingManager.AnchorablePaneControlStyle>
...
I get the border color changed but the rest of behavior is unusable:
I am not get the big picture yet for what you wanna get, but I think you have to edit the Theme.xaml file containing all AvalonDock Styles and have a look there at the following style:
<Style x:Key="AvalonDock_AnchorablePaneControlStyle" TargetType="{x:Type avalonDockControls:LayoutAnchorablePaneControl}">
<Setter Property="TabStripPlacement" Value="Bottom" />
<Setter Property="Padding" Value="0" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Foreground" Value="{Binding Model.Root.Manager.Foreground, RelativeSource={RelativeSource Self}}" />
<Setter Property="Background" Value="{DynamicResource AvalonDock_BaseColor8}" />
<Setter Property="Template">...
Then you can see that the Background property is binded to a DynamicResource. You have to change the value of AvalonDock_BaseColor8 resource accordingly to what you want to achieve.
Im just writing my own personal styles.
Everything is ok, no error inside styles.
I have following code
<Color x:Key="DialogButtonBorderBrushColor" A="255" R="177" G="177" B="177" />
<SolidColorBrush x:Key="BorderBrush" Color="{StaticResource DialogButtonBorderBrushColor}" />
There is a style for my dialog button.
<Style x:Key="DialogButtonStyle" TargetType="Button">
<Setter Property="MinWidth" Value="80" />
<Setter Property="MinHeight" Value="30" />
<Setter Property="BorderBrush" Value="{StaticResource BorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Background" Value="{StaticResource DialogButtonBackgroundColor1}"/>
</Style>
Im just using this dialogButtonStyle in xaml Button as a style.
But when I use this style I get following error:
#FFFAFAFA is not a valid value for the System.Windows.Controls.Panel.Background property on setter.
I have really no idea what to do with this.
Can you help me? Thanks.
<Setter Property="Background" Value="{StaticResource DialogButtonBackgroundColor1}"/>
Background property expects Brush value. Judging by the name of resource, DialogButtonBackgroundColor1 is a Color. You should use Brush resource similar to BorderBrush
I'm trying to figure out how to change the style of the AvalonEdit CodeCompletion window. However, I can't figure out the right combination of xaml style target/properties to change it. The main thing I'd like to do is get rid of the border, but maybe some additional changes as well.
Here is the xaml I've tried. None of it is affecting the UI.
xmlns:ae="clr-namespace:ICSharpCode.AvalonEdit.CodeCompletion;assembly=ICSharpCode.AvalonEdit"
<Style TargetType="{x:Type ae:CompletionWindow}">
<Setter Property="WindowStyle" Value="None" />
</Style>
<Style TargetType="{x:Type ae:CompletionWindowBase}">
<Setter Property="WindowStyle" Value="None" />
</Style>
<Style TargetType="{x:Type ae:CompletionListBox}">
<Setter Property="Background" Value="Red" />
</Style>
<Style TargetType="{x:Type ae:CompletionList}">
<Setter Property="Background" Value="Orange" />
</Style>
Use this style to remove border on window:
<Style TargetType="{x:Type avalonEdit:CompletionWindow}">
<Setter Property="WindowStyle" Value="None"></Setter>
<Setter Property="ResizeMode" Value="NoResize"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
</Style>
To make the styles affect the UI, you can put them in a resource dictionary xaml and parse that with (ResourceDictionary)XamlReader.Parse(ResourcesAsXaml).
Then assign the ResourceDictionary to the Resources property of the CompletionWindow.
Style definition in Resources/Shared.xaml (updated):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:Double x:Key="fullHeight" >26</system:Double>
<system:Double x:Key="halfHeight" >16</system:Double>
<Thickness x:Key="m">10</Thickness>
<Style TargetType="Button">
<Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
<Setter Property="Margin" Value="{StaticResource m}"/>
<Setter Property="Padding" Value="10"/>
</Style>
<Style TargetType="Label">
<Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
<Setter Property="Margin" Value="{StaticResource m}"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
<Setter Property="Margin" Value="{StaticResource m}"/>
</Style>
<Style TargetType="TextBox">
<Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
<Setter Property="Margin" Value="{StaticResource m}"/>
<Setter Property="Padding" Value="10"/>
</Style>
<Style TargetType="PasswordBox">
<Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
<Setter Property="Margin" Value="{StaticResource m}"/>
<Setter Property="Padding" Value="10"/>
</Style>
<Style TargetType="ListView">
<Setter Property="FontSize" Value="{StaticResource fullHeight}"/>
<Setter Property="Margin" Value="{StaticResource m}"/>
<Setter Property="Padding" Value="10"/>
</Style>
<Style TargetType="ComboBox">
<Setter Property="Margin" Value="{StaticResource m}"/>
</Style>
</ResourceDictionary>
Window:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Resources/Shared.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
User control:
<StackPanel Orientation="Horizontal">
<Label Content="Text" Background="AliceBlue"/>
<Label Content="{Binding DecimalValue, FallbackValue=50}" Background="Aquamarine"/>
</StackPanel>
Model:
private decimal _DecimalValue;
public decimal DecimalValue
{
get { return _DecimalValue; }
set
{
if (_DecimalValue != value)
{
_DecimalValue = value;
NotifyOfPropertyChange();
}
}
}
I'm using Caliburn.Micro if it makes any difference.
Result:
Why?
Update: After some Snooping, it turns out that the inner TextBlock of the first Label has margin of 0 and Value Source is Default and for the second it's 10 and Style.
Update 2: After reading up this question it turns out that defined TextBlock style should not be applied to TextBlocks inside Labels. So it seems that existence of binding on a Label somehow changes that.
You must have some other style affecting it.
My best guess would be check your Padding properties, because when I copy and paste your styles to a new project, the heights and margins are the same as your image, however the Padding is different.
Your Labels are actually getting rendered like this:
<Label>
<Border>
<ContentPresenter>
<TextBlock />
</ContentPresenter>
</Border>
</Label>
By messing around with Snoop, I can duplicate your image by altering the Padding of the Border object, so check your XAML to see if you have any implicit styles that change the Padding of your Border tags
Update
After adding the extra styles you've added to your question, I am able to reproduce the results you are getting.
The problem appears to be that the implicit style for your TextBlock is being applied to the TextBlock inside the bound label, but not to the unbound one.
It should be noted this only happens when binding to a decimal value, not to a string.
I suspect this is related to the fact that implicit styles are not meant to cross template boundaries, unless the element inherits from Control. Label inherits from Control, however TextBlock does not.
Since this only happens when binding to a numeric value, my best guess is that the process that determines how to draw a Decimal for Label.Content identifies the parent control as a Label, while the process that writes a string to Label.Content automatically knows to use a TextBlock, and does not apply the implicit styles.
I am using SL4 Business application with WCF RIA service. In my app, there is a loginForm. in the designer of loginform I can found username textbox and password textbox.But in .Xaml page its like the code given below.
<local:BusyIndicator x:Name="busyIndicator" BusyContent="{Binding Path=Strings.BusyIndicatorLoggingIn, Source={StaticResource ApplicationResources}}"
IsBusy="{Binding IsLoggingIn}">
<StackPanel Orientation="Vertical">
<toolkit:DataForm x:Name="loginForm"
Padding="10,0,10,0"
CurrentItem="{Binding}"
IsEnabled="{Binding IsLoggingIn, Converter={StaticResource NotOperatorValueConverter}}"
AutoEdit="True" CommandButtonsVisibility="None" HeaderVisibility="Collapsed"
AutoGeneratingField="LoginForm_AutoGeneratingField"
Style="{StaticResource LoginDataFormStyle}" />
</StackPanel>
</local:BusyIndicator>
My question is I need to style the username textbox as well as password textbox in the dataform. How can I do this? From where can i access these controls?
Those controls are generated by the DataForm control. You basically need to put a default style for TextBox and PasswordBox under the root Grid's Resources. I gave them a massive font size of 50. You just need to replace them with your own styles.
<!-- LoginDataForm Style -->
<Style x:Key="LoginDataFormStyle" TargetType="dataControls:DataForm">
<Setter Property="Width" Value="370"/>
<Setter Property="AutoCommit" Value="True"/>
<Setter Property="AutoGenerateFields" Value="True"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="DescriptionViewerPosition" Value="Auto"/>
<Setter Property="LabelPosition" Value="Auto"/>
<Setter Property="HeaderVisibility" Value="Collapsed"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="0,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="dataControls:DataForm">
<Grid dataControls:DataField.IsFieldGroup="True">
<Grid.Resources>
<Style TargetType="TextBox">
<Setter Property="FontSize" Value="50"/>
</Style>
<Style TargetType="PasswordBox">
<Setter Property="FontSize" Value="50"/>
</Style>
<Style x:Key="ButtonGeneric" TargetType="Button">
Hope this helps. :)
The form automatically generates the fields for you (the AutoGenerateFields property is set to True by default). However, in the case of the LoginForm in the Silverlight Business Application template, the form has a handler for the AutoGeneratingFields event (LoginForm_AutoGeneratingField as shown in your xaml). In this handler, the username textbox and the password box are created, databound and added to the form. You can jump in there and do the customization you want by setting their properties.
Hope this helps :)