I've got a (hopefully) easy one for you today.
I'm looking to remove the dashed border of a WPF element when it's been selected via keyboard navigation, simply because said marquee is ugly and inconsistent with other styling. I'm only looking to do this on the items of a particular ListBox. I'm hoping there is some SystemColors key I can set, or some other Style property.
Thanks,
-Logix
I found the answer after plenty more searching. Apparently 'dotted line' was the search term I needed, not 'marquee'.
Anyway, here's the solution (from this answer):
In the ListBox style, set:
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
Related
I am making some things in silverligth with marked up text in XAML.
Everything is going fine until i came up with this.
I am trying to give my text a background color but it says the property does not exist.
the property for a foreground does exist.
is there a way to still give my text parts a background color?
image in link:
http://img146.imageshack.us/img146/537/highligths.png
This is one of those annoying Silverlight vs. WPF differences. Neither TextBlock nor Run elements provide a Background property in Silverlight. You need to wrap them in a Border:
<Border Background="Red">
<TextBlock>Test please ignore</TextBlock>
</Border>
Thus it's annoyingly involved to do precisely what you want, but possible. If the text you want to display is not well known ahead of time, your best bet is to look at a third party RichTextBox control such as Telerik's RadRichTextBox.
Please tell me you did that with Textblock and Runs. I think the Run element can support foreground and background properties. I know you can twist the content to support both you just have to be clever about the controls inside the Textblock.
When creating an app based on the Silverlight Business Application template, a number of styles are generated in Styles.xaml. These, for the most part, are self-explanatory.
I am interested in giving the Login form a dark background, which I can accomplish by manipulating the LogRegWindowStyle style. Now, I want to change the default black text of the User name and Password labels to something lighter, but what do I do?
The LoginTextStyle style seems to be the most likely candidate but it is not referenced anywhere and setting a Foreground value does not seem to have an effect. So why is it there?
Finally, the labels turn red when an error occurs so is this achieved by a style or is it hard-coded somewhere? How would I change it if there wasn't enough contrast with the background?
the login text style is inherited from the loginFrom style LoginDataFormStyle. If you set a Foreground color in the LoginDataFormStyle, the foreground of the text will also be changed.
<!-- LoginDataForm Style -->
<Style x:Key="LoginDataFormStyle" TargetType="dataControls:DataForm">
<Setter Property="Foreground" Value="Gray"/>
To change the color of the Labels, you can create your own DataTemplate of your loginFrom and put in whatever Labels you need. Then you can create a style for your Label and change the Color from 'Red'(default color) to something you like in the Label's Invalid visual state.
Hope this helps. :)
I have a binding for ListViewItem, which is under gridview/listview/scrollviewer.
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
There's one problem occurred to me:
After I press "CTRL+A" in a ListView/GridView, all items that are currently in the ScrollViewer area will have "IsSelected" set to true.
For all other items in the list, but NOT in the current viewable area of the scroll viewer, the "IsSelected" will NOT be set to "true" unless I scroll them into viewable area manually.
I want to ask is this by design? If not, what I may go wrong?
Thank you.
You are probably using virtualization. So only the "containers" (i.e. ListViewItem) needed to fill the view will be created. You can disable virtualization by setting VirtualizingStackPanel.IsVirtualizing to false on your ListView. This does have a performance hit if you have a lot of data though.
I am relatively new to the WPF scene, and am having a problem understanding how styles are reused amongst controls.
My example situation is this, I'm making a control that needs a Toggle button. I want this ToggleButton to look like the 'expand' Button on a TreeViewItem. How would apply the TreeViewItem's button style to my own button?
From my searching I have a feeling that it isn't possible without copying XAML, but I can't justify to myself why anyone would make a UI framework that limited.
Thanks in advance.
I'm not sure there's a way of retrieving the default style/template from something and applying it to another control in XAML, although you may be able to to it in code. Although that would pose the problem that you just want to get the button part of the template and it's easier (not to mention cleaner) just to write a new style rather than hacking around to get just that part of the template.
The problem with restyling buttons is that when pressed they will go back to their default pressed appearance, same for when they are hovered. What you want to do is change the ControlTemplate of the button.
When I was starting out in WPF I found this tutorial
to be quite a useful introduction to the process.
I'd recommend getting a copy of ShowMeTheTemplate to give you access to most of the default templates for controls as that will save a lot of the basic work and give you an insight into how the controls work.
When you've created your control template (or any style/template for that matter), you can store it in a resource dictionary and apply it to controls by referencing it from the relevant property using the StaticResource markup extension.
Example:
(In a resource dictionary, for example App.Resources):
<Style x:Key="myStyle" TargetType="Button">
<Setter Property="Width" Value="70" />
</Style>
Used in a button:
<Button Style="{StaticResource myStyle}" />
Hope this helps get you started.
In Expression Blend you can create a font-size of say 18 and then create a "font-size resource".
Coming at this from HTML/CSS, I cannot think of when I would want to make a style for a "font-size" and one for a "font-style" and one for a "font-weight". Instead I want to make a font called "CompanyHeader" and have 10 different attributes set in it, e.g. font-weight, font-style, font-size, color,etc.
Why is this different in Expression Blend, XAML, what is the sense of making a style/resource for each attribute?
this graphic shows how you can click on a little button on each attribute to change it into a resource:
alt text http://tanguay.info/web/external/blendStyles.png
I have no experience with Blend, but styles in XAML can include more than one attribute, more then that, since unlike css you can only apply one style to an element you can't combine multiple one-attribute styles.
Here is an example for a style that set multiple properties:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="MyStyle" TargetType="{x:Type Label}">
<Setter Property="Width" Value="125"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Background" Value="Red"/>
</Style>
</Page.Resources>
<Label Style="{StaticResource MyStyle}"/>
</Page>
Note that if I wanted to break the style into 3 smaller styles each setting one property I couldn't use them because the Label's Style property can only accept one style.
I think they likely allow for the creation of single resources for FontFamily, FontWeight, etc. to allow them to be used across many styles in the application. By placing a single property in a resource you can effect all styles using that resource at once. If you weren't using a resource but were attempting to use a consistent FontFamily across your whole application (or a portion of it) then you had to go through each style one at a time in order to update it.
In order to make a style with multiple properties in blend you can do the following:
Select the control you wish to style (the control's type will be used as the TargetType for the style)
From the menu select Object->Edit Style->Create Empty
Enter the Key you would like to assign to the style (this is the name that you will use to reference the style)
Go to the properties tab and begin to apply the look/feel that you want for that style
It allows you to reuse the font details at am more granular level than having to define all elements of the font definition. You might have several styles that all inherit from the same font-size definition. Your designer can then change the font-size and all the styles that use it then automatically have an updated appearance.
Each instance of a font will use its own resources, doesn't matter if multiple such defenitions refer to same font.
Using same font in two different styles will end-up with two instances of the font (when the styles are applied). Instade, you can defined the font as a style of its own and use the style with-in other styles. In this case, once runtime instance of the font resource is used by both styles.
If you have very complex resource dictionaries (say for example you are creating a theme), it is a good idea to define geanular assets (like a specific color brush or font) as independent resource (or named style) and use them in other complex styles to conserve system resources.
On your question on Blend, it simpley enforces this best practice.
This is possible by creating a helper class to use and wrap your styles. CompoundStyle mentioned here shows how to do it. There are multiple ways, but the easiest is to do the following:
<TextBlock Text="Test"
local:CompoundStyle.StyleKeys="headerStyle,textForMessageStyle,centeredStyle"/>
The blog post talks about Win8 and Windows Phone, but the same code works for WPF as well (minus the Utilies class which is not needed)
Hope that helps.