How can I disable the visual style only for the tooltip, not for all the application, because if I do so it will change my toolstrip visual style and it will look ugly?
What I have:
What I want:
For some reason it just won't work. Thanks everybody.
I believe you are going to want to look into using the Tooltip.OwnerDraw Property. The example program in the MSDN Link has a style like what you are wanting.
If you're looking for a WPF solution you'll want to override the default template for the
ToolTip. Mark Hall's answer is correct if you're looking for a WinForms solution.
Update:
Posted this before the comment was added and the question was re-tagged as WinForms. I leave it here for anyone looking for a WPF solution.
XAML:
<ToolTip>
<ToolTip.Style>
<Style TargetType="{x:Type ToolTip}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="LightGoldenrodYellow" BorderBrush="DimGray" BorderThickness=".5" Padding="5">
<TextBlock Text="This is text"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToolTip.Style>
</ToolTip>
Related
I've this code in C# to create a button as a child of a StackPanel:
`
Button myButton = new Button();
//All button stuff (Background, text...).
myStackPanel.Children.add(myButton);
`
But, as every button, it highlights every time the mouse is over or when I click it. Is there any way to change that in an easy code (I'm still new to C#) can remove that highlight.
I don't know how to do this. I haven't seen anything explaining this and the only codes I could find were in XAML, and I didn't understand them so couldn't translate them to C#.
The problem is all the code I find is about retemplating the XAML code. What I need is to do what I mentioned in C#, as the control is created from scratch in C#.
I took a look at a few of the answers for this and didn't see any I liked much.
WPF controls are lookless, meaning they have fixed behaviour but not specific look to them. You can re template a wpf control to pretty much anything you can describe in xaml. Many wpf controls have quite complicated templates.
Here's one way to template a button as described.
I've put this style in my window's resources. Usually such styles are in resource dictionaries which are merged in app.xaml.
<Window.Resources>
<Style x:Key="NoMouseOverButtonStyle" TargetType="{x:Type Button}">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="BorderBrush" Value="LightGray"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}" >
<ContentPresenter Margin="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Button Style="{StaticResource NoMouseOverButtonStyle}"
Content="This is my Button"
Click="Button_Click"
HorizontalAlignment="Left"
VerticalAlignment="Top"
/>
</Grid>
</Window>
The button references the style as a resource.
That style sets some defaults so the button has a border you can see but over ride.
The contentpresenter is critical because this is where whatever you make content of your button will appear.
If I set an actual value on a button then that will over ride the style.
Hence
<Button Style="{StaticResource NoMouseOverButtonStyle}"
Content="This is my Button"
Click="Button_Click"
HorizontalAlignment="Left"
VerticalAlignment="Top"
BorderBrush="Red"
/>
Gives me a red border on my button.
A lightgray border is rather simpler than a button has by default.
You could reproduce that. Maybe that'd be an interesting learning exercise.
Lookup the button template on msdn.
Google: "wpf button template msdn"
Take a look at that. Brace yourself - it is complicated.
See the button border brush is hard coded in the template?
Change the style above so it does the same.
Clue:
<Setter.Value>
here is whats getting on my nerve:
My job si to restyle application, so i didn’t wrote it, i have to slightly change the code(.cs or .xaml). Problem lies within avalonDock…i cant remove borders from panels, or change its color.
This is part of code, where dockingManager parts are defined(lets call it MainView.xaml)
<ad:DockingManager Name="dockingManager" >
<ad:ResizingPanel Orientation="Horizontal">
<ad:DockablePane ad:ResizingPanel.ResizeWidth="50" Name="navigatorHostCtrlPane" >
<ad:DockableContent Name="navigatorHostCtrl" Title="{StaticResource Navi}" IsCloseable="False" Background="Transparent"/>
</ad:DockablePane>
<ad:ResizingPanel Orientation="Vertical" >
<ad:DockablePane Name="mainPane" >
<ad:DockableContent x:Name="mainHostCtrl" Title="{StaticResource Sc}" AllowDrop="False" IsCloseable="False" ClipToBounds="False" Background="White"/>
</ad:DockablePane>
<ad:DockablePane ad:ResizingPanel.ResizeHeight="250" >
<ad:DockableContent Name="dataHostCtrl" Title="{StaticResource Dt}" IsCloseable="False" Background="White"/>
</ad:DockablePane>
</ad:ResizingPanel>
</ad:ResizingPanel>
</ad:DockingManager>
And this is where parts are set in .cs file(MainView.xaml.cs) like this:
BindRegionToGui(regionManager, RegionNames.NavigatorRegion, navigatorHostCtrl);
And BindRegionToGui():
private static void BindRegionToGui(IRegionManager regionManager, string regionName, UIElement content)
{
var reg = (AvalonDockRegion)regionManager.Regions[regionName];
reg.Bind(content);
}
I cant change style of outer border even in element by setting BorderThickness = “1“, or in style definition:
<Style x:Key="{x:Type ad:DockablePane}" TargetType="{x:Type ad:DockablePane}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property=“BorderThickness“ Value=“0“/>
</Style>
I can alter whole dockingPanes by setting style like this(after some example):
<Style TargetType="{x:Type ad:DockablePane}">
…
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ad:DockablePane}">
<Border
Background=….
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
But with this – the content won’t show up. I assume, that content.template overrides it, but i dont know how i can put application’s defined panels into it.
Sorry if this is stupid question but i am really beginner in xaml / c# so i’m in kind of a bad situation.
I restyled AvalonDock in pretty dumb way. I've downloaded source code from http://avalondock.codeplex.com/SourceControl/list/changesets, changed generic.xaml and rebuild whole library.
I want to create a column chart using the WPF toolkit, but I want to hide the Y axis and display the dependant value for each column below the X value.
Is this possible?? If not, what other way could be used to get this result??
Thanks in advance.
Yes, you can hide the Y-axis. You should add the y-axis explicitly to the Axes property of the chart and set the Opacity property, like this:
<charting:Chart.Axes>
<charting:LinearAxis Orientation="Y" Opacity="0" />
</charting:Chart.Axes>
As to the second question, you should change the AxisLabelStyle property. I answered a similar question here, you can look at the code and change the ControlTemplate according to your needs.
The template will look something like this, don't forget change bindings:
<Style x:Key="twoLabelsStyle" TargetType="charting:AxisLabel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:AxisLabel">
<StackPanel>
<TextBlock Text="{Binding Month}" />
<TextBlock Text="{Binding Number}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Anyway if it will not still work - add your source code to your question, it can help much better.
is there any way to override the default style of the radiobuttons, if it is placed in a menu?
but if it is in the window, it should look like ever. but i will not use x:key. it should found this automatically.
I see two solutions:
Create style with x:Key but place it in Menu.Resources - that way it will be only applied to menu items.
ItemsControls (Menu is one) have property called ItemContainerStyleSelector. You can create Your own StyleSelector and set style depending on container type.
it is very easy, if you know how :)
<style TargetType="{x:Type Menu}">
<Setter Property="Template>
<Setter.Value>
<ControlTemplate TargetType="{x:Type Menu}">
<ControlTemplate.Resources>
<Style Targettype="{x:Type Radiobutton}>
</Style>
</ControlTemplate>
<StackPanel IsItemsHost="True" Width="{TemplateBinding Width}" Height= {TemplateBinding Height} />
</Setter.Value>
</Setter>
</style>
you have to control the writing of the keywords, because i write it so and not on Visual Studio.
override the menu standard with a stackpanel, because i had found no other way to set the Resources.
It is easy, but without the answer from Varius, i didn't found this.
You have to do the same for MenuItem.
I post this, because i think, it maybe would help other peoples with the same problem.
i had searched long time and find nothing.
I have a user-control and I want to use it in some other project. There is no problem when I set some value to its properties directly:
<local:MyUserControl prop1="val1" prop2="val2">
...
</local:MyUserControl>
But I can't apply a style to it. I tried:
<Window ...>
<Window.Resources>
<Style x:Key="MyUserControlStyle" TargetType="{x:Type local:MyUserControl}">
<Setter Property="prop1" Value="val1"/>
<Setter Property="prop2" Value="val2"/>
</Style>
</Window.Resources>
<Grid>
<local:MyUserControl Style="{StaticResource ResourceKey=MyUserControlStyle}">
...
</local:MyUserControl>
</Grid>
</Window>
Where did I wrong? -Thanks
Using dear #Mario Vernari's instructions, I found it out that the problem was due to a bad strategy which I'd used to create my UserControl. I wanted to create a UserControl that be able to hold some other ones. So I had tried this:
<UserControl x:Class="MyNamespace.MyUserControl"
...
Style="{DynamicResource ResourceKey=MyUserControlStyle}">
<UserControl.Resources>
...
<Style x:Key="MyUserControlStyle" TargetType="{x:Type UserControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type UserControl}">
<Border BorderBrush="{Binding Path=DP1}">
...
<ContentPresenter ... Content="{TemplateBinding Content}"/>
...
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
</UserControl>
Where DP1 is a dependency property of type Brush. The UserControl which has been created through this way works if you set its properties (like DP1) directly. Absolutely this is not the true way as #Mario told me:
...When you use an UserControl, it means that you already know its layout, and there is no need to style the control further. You are defining its style twice at the same time thus results a collision...
And he added:
Instead, you should use a CustomControl; Define the default style in the Themes folder (if you own regular Visual Studio, it makes automatically). Afterward, you may override the default style in your own app. In the same way you would do for a normal base class and its derived.
Follow this:
http://www.codeproject.com/KB/WPF/WPFCustomControl.aspx ...
Obviously, in this case we need to derive our lookless control from ContentControl class (instead of Control class). You may take a look at this & this to master the details.
Here, I give thanks to #Mario again. ;)
You are giving Style="{StaticResource ResourceKey=MyUserControlStyle}".
It's just - Style="{StaticResource MyUserControlStyle}".