Header style datagrid silverlight - c#

I am using silverlight and cant edit the header style of the data grid.
<sdk:DataGridTemplateColumn.HeaderStyle>
<Style>
<Setter Property="FontSize" Value="14" />
<Setter Property="Background" Value="Pink"/>
</Style>
</sdk:DataGridTemplateColumn.HeaderStyle>
It's written that member FontSize and Background are not accessible.
What should i do?

Try changing it to:
<sdk:DataGridTemplateColumn.HeaderStyle>
<Style xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
TargetType="primitives:DataGridColumnHeader">
<Setter Property="FontSize" Value="14" />
<Setter Property="Background" Value="Pink"/>
</Style>
</sdk:DataGridTemplateColumn.HeaderStyle>
It should allow you set the properties with that namespace and target type added. You could also just add the namespace to the user control, instead of putting it in the style.

Related

What is the correct way to change the Value of multiple Styles?

I am currently trying to implement a Dark Mode to my application. I have multiple ResourceDictionaries, one Window and multiple UserControls. In my MainWindow I've created a Command that is supposed to change the Design during runtime.
One of my ResourceDictionaries looks like this:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="SecondaryBorder" TargetType="Border">
<Style.Setters>
<Setter Property="Background" Value="#272726"/>
</Style.Setters>
</Style>
<Style x:Key="WindowTheme" TargetType="Window">
<Style.Setters>
<Setter Property="Background" Value="#3c3c3b"/>
</Style.Setters>
</Style>
<Style x:Key="HeadlineReports" TargetType="TextBlock">
<Style.Setters>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="FontFamily" Value="Rubik Light"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style.Setters>
</Style>
</ResourceDictionary>
Here I would like to change the following values: #272726 → #55ffff and #3c3c3b → #FFFFFF.
At first, I thought that I could create a global value for each colour and simply change the value with code-behind, however, I now learned that you are not supposed to do that with ResourceDictionaries.
What would be the correct way to change the colour throughout the whole application?
Create a copy of the existing ResourceDictionary and edit the values in this copy.
When you want to switch theme, you then remove the existing resource dictionary and merge the new one. Something like this:
App.Current.Resources.MergedDictionaries.Clear();
App.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
Source = new Uri("dark.xaml")
});

How change focused TextBox style on Windows 10 UWP XAML?

How apply a custom style (from a resource) to a TextBox when it has the focus.
My usual solution
<Style TargetType="TextBox" x:Key="NoteBox">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
Does not affect the focused or selected state.
You have to edit the Setters in its VisualState. You can get the default template here.
Just copy it and edit the values in the Focused VisualState.

WPF The member "TabNavigation" is not recognized or is not accessible.

I am trying to convert my silverlight application to wpf application. In the custom controls i have this piece of code:
<Style TargetType="ComboBox" x:Name="CcsDataGridDynamicCellComboBox" x:Key="CcsDataGridDynamicCellComboBox">
<Setter Property="Padding" Value="6,2,25,2" />
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="BorderThickness" Value="1"/>
/////////////this is where i am facing error:
<Setter Property="TabNavigation" Value="Once" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderBrush">
<Setter.Value>
The error i am having is:
Error 1 The member "TabNavigation" is not recognized or is not accessible. C:\Users\sahluwai\Desktop\cusControls2\leitch\HarrisSilverlightToolkit\Toolkit\Source\Controls\Table\Themes\CcsDataGridDynamicCellComboBox.xaml 61 17 Table
So This means that "TabNavigationProperty" is not available in wpf.so what should i use instead or is the default behavior of wpf the same as i am trying to specify(ie. TabNavigationproperty is default to "once")?
Not positive, but I think the property you are looking for is KeyboardNavigation.TabNavigation.
Not sure on this, but I think what you would do is instead of setting your TabNavigation Property, you could set the TabIndex Property to whichever value you want the combo box to be in the tab order. For example, if you sit the TabIndex value to 4, then if you hit tab 4 times, you will end up on your comboBox. Here is another article you can check out. WPF Tab Key Navigation.

Is there any settings in wpf to align buttons in fixed distance

App contain more than 30 buttons but there alignments are incorrect
my question is:
Is there any property for arranging all 30 button in fixed length and height?
If you want share same setting between all 30 buttons you should use Styles:
<Style TargetType="Button">
<Setter Property="Width" Value="20" />
</Style>
After you'll have all buttons with width 20. This is happening due to a concept called implicit styles. Any time you are specifying style without Key it will automatically apply it to all TargetTypes without explicitly defined style.
Have you tried using a Style to declare your Button dimensions? Try adding this into your Resources section:
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Height" Value="24" />
<Setter Property="Width" Value="150" />
</Style>
</Window.Resources>
This will affect all Buttons within scope of the Style, but you could change it to this...:
<Style x:Key="SizedButton" TargetType="{x:Type Button}">
<Setter Property="Height" Value="24" />
<Setter Property="Width" Value="150" />
</Style>
... and then explicitly assign the Style to each Button:
<Button Content="Something" Style="{StaticResource SizedButton}" />

Basing A Style Off A Dynamic Resource

It seems something like this is not allowed. Any workaround?
<Style x:Key=MyDerivedStyle TargetType="{x:Type Button}"
BasedOn="{DynamicResource GlobalButtonStyle}" />
<Style x:Key="GlobalLabelStyle" TargetType="{x:Type Button}">
I get the error:
A 'DynamicResourceExtension' cannot be set on the 'BasedOn' property of type 'Style'. A 'DynamicResourceExtension' can only be set on a DependencyProperty of a DependencyObject.
If I change it to StaticResource, the style does not appear in my control.
Two issues here:
First, your global style needs to appear before your derived style (either in the same resources section, or by merging in the appropriate ResourceDictionary before attempting to define the derived style.
Also, you need to explicitly define the Style in your button:
<Button x:Name="btnOne"
Style="{StaticResource MyDerivedStyle}"
Content="Derived" />
Note that in this case you aren't creating a Dynamic Resource (i.e. one that needs to be reloaded). It is static, as a Style that is being used for a BasedOn needs to be.
Firstly you need to place Based Style and after that the Style that using this Bass Style:
<Style x:Key="ComboBoxItemStyleSpecial"
BasedOn="{StaticResource ComboBoxItemStyleDefault}"
TargetType="{x:Type ComboBoxItem}">
<Setter Property="BorderBrush"
Value="Lime" />
<Setter Property="BorderThickness"
Value="3" />
</Style>
<Style x:Key="ComboBoxItemStyleSpecialFont"
BasedOn="{StaticResource ComboBoxItemStyleSpecial}"
TargetType="{x:Type ComboBoxItem}">
<Setter Property="FontSize"
Value="40" />
<Setter Property="FontFamily"
Value="Aharoni" />
</Style>

Categories