I've just installed the Silverligt toolkit 4 to get access to some of the nicely styled controls.
However, when I surround a button in a grid with the theme, I get the following result:
http://screencast.com/t/aiWsArdb
Both of the squares are grid controls, with a solid color background. But when I apply a theme to the button in the left grid, the entire grid gets styled. That's not really what I am after. Anyone know how I can avoid this? Basically I just want the theme to apply to the button only, and not the parent grid.
The XAML is:
<dark:ExpressionDarkTheme><Button Content="Button" Name="button1"/></dark:ExpressionDarkTheme>
The ExpressionDarkTheme has a default Black Background, try setting it to null.
<toolkit:ExpressionDarkTheme Background="{x:Null}">
<Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/>
</toolkit:ExpressionDarkTheme>
Related
How do I configure WPF to make its controls use the sizes recommended by Microsoft?
For example, a button should be 23 pixels high, including a 1 pixel transparent border. How do I implement the transparent border? Button.BorderBrush controls the visible border.
Another example is a single-line text box, which should be 23 pixels high.
Do I have to style everything by hand? Or is there way to cause the controls to default to a native Windows user experience?
Update: Here's a visual of some of the differences.
WPF controls:
Standard Windows controls: (from the Common Item Dialog, e.g. in Notepad, clicking File > Open)
This isn't a perfect comparison, since the in the Common Item Dialog, the file name box is a ComboBox, not a TextBox. I tried comparing the Print Setup and Print dialogs (also from Notepad), but they don't use the same size buttons or even the same font as the open file dialog. I keep forgetting that I'm dealing with Microsoft here, not Apple.
There is a distinction regarding the button that is consistent through all of Notepad's dialogs, which WPF doesn't match by default. If the button is a default button, the border is thicker in Notepad. The button's transparent border turns blue. For a Notepad non-default button, you can click one pixel outside the visible border and still hit the button. This doesn't work for the WPF button.
Flexibility is nice, but native it-just-works-and-looks-great controls would be really nice. If there's a drop-in solution where I don't have to think about this stuff, that would be great.
Here's the XAML for the WPF controls:
<StackPanel Name="controls" Margin="20">
<TextBox Text="Default TextBox" />
<TextBox Height="23" Text="TextBox with height 23" />
<Button Content="Cancel" />
<Button Height="21" Content="Cancel" IsDefault="True" />
</StackPanel>
And the code-behind:
foreach (Control control in controls.Children) {
control.Margin = new Thickness(0, 10, 0, 10);
control.VerticalContentAlignment = VerticalAlignment.Center;
}
I have two C# WPF solutions. For some reason on solution #1, the default values for UI elements do not match the default values for solution #2.
I am trying to find where the default values for this solution are stored.
Here is an example.
I generate a new button using the XAML code:
<Button Content="Button" HorizontalAlignment="Left" Margin="0,0" VerticalAlignment="Top" Width="75"/>
Solution 1:
I create a new button.
The button's default height is 22 pixels. The button's default font is "Segoe UI" and the default font size is 12px.
Solution 2:
I create a new button.
The button's default height is 28 pixels. The button's default font is "Calibri" and the default font size is 18px.
http://i.imgur.com/CzAz7Vu.png is a screenshot showing the properties that I am seeing being displayed. Where can I find what is setting these default values per solution since it does not appear to be stored directly in the XAML?
Edit: You were correct! The default font style and size were being defined in the Window XAML code.
<Window x:Class="test.test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
FontFamily="Calibri"
FontSize="16"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test" Height="{Binding SystemParameters.PrimaryScreenHeight}" Width="{Binding SystemParameters.PrimaryScreenWidth}" WindowStartupLocation="CenterScreen" WindowState="Maximized">
Look at the container control that the buttons are enclosed in. The Button's implicit style can be set in many ways, so the button can pickup these default values from many places.
For example, if the button is inside a 3rd-party custom control, then the default font may be set to Calibri, rather than the global default of Segoe
I am building a user control in WPF and put a few buttons in a stackpanel laying inside a grid. Problem is that when I build the app and run it, the buttons "sail around" and don't stay where I put them in the designer window. Is there any attribute I'm missing(or some sort of container?)?
Thanks.
Try setting the alignment properties of your grid:
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
...
</Grid>
I am using WPF split button which is inherited from
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
The issue is I want to disable , the button ' the one below(Right side of Button 'Conf' in below 'downarrow present in the below fig) , If user clicks on Left side of the button the rightside should be disabled and the button(leftside) background should change to yellow.please find below the xaml , I am using the wpf split button , dropdown content in this case .please let me know if you have any idea
<extToolkit:SplitButton x:Name="ABCbutton"
VerticalAlignment="Center"
Command="{Binding ACommand}"
FontSize="16>
<TextBlock HorizontalAlignment="Center"
IsEnabled="{Binding IsEnabled, ElementName=AButton}"
Text="A"/>
<extToolkit:SplitButton.DropDownContent>
<StackPanel>
<Button Command="{Binding BCommand}"
Padding="3"
Style="{DynamicResource
DropDownButtonMenuButton}">
<TextBlock Margin="0,3,6,3"
Text="B"/>
</Button>
<Button Command="{Binding BCommand}"
Padding="3"
Style="{DynamicResource
DropDownButtonMenuButton}">
<TextBlock Margin="0,3,6,3"
HorizontalAlignment="Stretch"
Text="C"/>
</Button>
</StackPanel>
</extToolkit:SplitButton.DropDownContent>
</extToolkit:SplitButton>
In a case like this, you will likely be better off creating your own control. The split button can't really handle what you are talking about without a good deal of modification.
Essentially your new control will consist of two buttons, visually styled so that they look like they blend together. Each will have it's own background and enabled property. Add a ViewModel to help control behaviors and set properties, and I think you would be in business. Keep in mind that all of the controls that are supplied in any of the toolkits, frameworks, control packs, etc are made with the primitive types of drawing and framework elements (line, rectangle, border, content presenter, panel, etc) with specialized behavior code.
I end up making a lot of custom controls just because there is not one that perfectly replicates what I want.
I want a custom Control in WPF which have a appearance similar to HTML, we use for showing Images in the centre of the screen with the whole screen locked and only image is showing.
I dont want to show images, I want to show UserControls within this section.
Can someone give suggestions of this?
In your Window, put all your controls in a single Grid, with a Border control (that contains your image) as the last item in the Grid (which means it will display on top of the other items). Toggle its Visibility via binding or code. Adjust styles as required.
<Window>
<Grid>
<!-- window controls go here --->
<Border Visibility="..." Background="#80000000"> <!-- EDITED -->
<!-- overlaid image (and/or other controls) goes here --->
<Image
Source="..."
Width="..."
Height="..."
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<Grid>
</Window>
In Windows applications this is generally achieved using a modal dialog, i.e. you create a normal WPF window and show it using ShowDialog.