In a WPF window I got a CheckBox containing an image, like this:
<CheckBox>
<Image Source="/Bsoft.Clients.Warenwirtschaft;component/Resources/MyImage.png" />
</CheckBox>
Using this, the checkmark is displayed left to the image.
Is there an easy way to move the checkmark to below the image?
I do not know of an easy way to do this.
You could either use some panel and have a checkbox independent from your image...
<StackPanel>
<Image .../>
<CheckBox .../>
</StackPanel>
Which might not be too much trouble if encapsulated in a UserControl.
Or you change the ControlTemplate of the CheckBox, which is more difficult i think. Default templates can be found on MSDN.
Related
I want to change the graphical UI elements in WPF.
For example, I want to use a kind of a stack panel, but on the other hand I want to show my details in a star, or circle, etc.
Maybe setting a bitmap as a background, but I am working with lots of Data using zoom tool.
I found tutorials, documentation only for changing attributes of "old components", but nothing to make new ones.
Great resource for WPF beginners is www.wpftutorial.net
One of the best idea of WPF is separation of concerns:
UI Control = Logic in Code/XAML + Template
Using templates in XAML we can vary representation without modifying the control.
For example, if there is a need in creation of list of items. Then we can use ListBox control:
<ListBox>
<ListBoxItem>USA</ListBoxItem>
<ListBoxItem>UK</ListBoxItem>
</ListBox>
By default LisboxItem internal part is just binded TextBlock.
Now making UI modification without changing control source code:
<ListBox ImageSource="{Binding PathToSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource ProjectIcon}"/>
<TextBlock Text="{Binding Path=PropertyName}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
there appears image and text.
If there is a need in creating exclusive control then you can always use Custom Control.
Using raster images (e.g. PNG) is not good point, especially with zoom behaviour. If it is possible better to use vector images, that can be created in XAML or imported from SVG.
I am wondering if there is a way to bind the current ContextMenu item to a property in WPF without first clicking on it.
For example:
<MenuItem MaxHeight="20"
HorizontalAlignment="left"
Header="Radio Group"
Name="cmRadio"
ItemsSource="{Binding RadioGroups, Mode=OneWay}" />
I'm hoping to be able to figure out what item the mouse is over before clicking.
Sorry for the lack of description ahead of time.
There are lots of "mouseover" events you could use, some totally in XAML.
Similar Problem
See farther down for the XAML answer.
I have an Image control on my WPF Window and I'd like to display a complex tooltip when the mouse is hovering over this Image.
Imagine like a spell icon in World of Warcraft, you mouse over and the spells tooltip is shown.
How can I do this in XAML?
You can achieve it like this:
<Image>
<Image.ToolTip>
<ToolTip.Content>
<!--...content goes here. -->
</ToolTip.Content>
</Image.ToolTip>
</Image>
You just put whatever you want into the ToolTip property in XML element syntax.
I recommend doing the following to what x0r stated:
<Image ToolTipService.ShowDuration="1440000">
<Image.ToolTip>
<ToolTip.Content>
<!--...content goes here. -->
</ToolTip.Content>
</Image.ToolTip>
</Image>
This leaves the tooltip open for 24 hours (yes, it's a long time). This is just a way to override that annoying 5-second rule.
I am trying out new styles with silverlight, and I created a new button skin with blend that consists of a border and a textblock. Wondered if there is a way to change the the text of the textblock when the the button's content(text) property is changed.
The binding would look like this:
<TextBlock Text="{TemplateBinding Content}"/>
The problem is when I try to set the content to something other than text:
<Button>
<Button.Content>
<Rectangle Fill="#FFB51111"/>
</Button.Content>
</Button>
In this case using the ContentPresenter would work better. It uses the same binding expression, but can display more than text. But all that is really up to you.
I don't really get what your trying to do. Normally, you include a TextBlock like that as a part of the button content.
Use a ContentPresenter rather than a TextBlock in your Template.
I'm trying to make an item on ToolBar (specifically a Label, TextBlock, or a TextBox) That will fill all available horizontal space. I've gotten the ToolBar itself to stretch out by taking it out of its ToolBarTray, but I can't figure out how to make items stretch.
I tried setting Width to Percenatage or Star values, but it doesn't accept that. Setting Horizontal(Content)Alignment to Stretch in various places seems to have no effect either.
Unfortunately it looks like the default ControlTemplate for ToolBar doesn't use an ItemsPresenter, it uses a ToolBarPanel, so setting ToolBar.ItemsPanel won't have any effect.
ToolBarPanel inherits from StackPanel. By default its Orientation is bound to the parent ToolBar.Orientation, but you can override this and set its Orientation to Vertical with a Style and this will allow items to stretch horizontally:
<DockPanel>
<ToolBar DockPanel.Dock="Top">
<ToolBar.Resources>
<Style TargetType="{x:Type ToolBarPanel}">
<Setter Property="Orientation" Value="Vertical"/>
</Style>
</ToolBar.Resources>
<ComboBox HorizontalAlignment="Stretch" SelectedIndex="0">
<ComboBoxItem>A B C</ComboBoxItem>
<ComboBoxItem>1 2 3</ComboBoxItem>
<ComboBoxItem>Do Re Mi</ComboBoxItem>
</ComboBox>
</ToolBar>
<Border Margin="10" BorderBrush="Yellow" BorderThickness="3"/>
</DockPanel>
You can then use a Grid or something in place of the ComboBox above if you want multiple items on a line.
Try putting a horizontal StackPanel in the ToolBar and then the element you want inside of that StackPanel.
Have you tried wrapping your item in a Grid, not in a StackPanel?
You need a special custom panel like auto stretched stack panel, and replace the toolbarpanel. Check this out you can find one panel there
http://blendables.com/products/productsLayoutmix.aspx
I've had this same problem for a while, and there is very little help available online.
Since it doesn't sound like you need all the extra functionality of a Toolbar (collapsible/movable trays), why not just use a Top-docked Grid, and tweak the background a little to make it look like a standard toolbar?