How to put text into circle in WPF XAML template? - wpf

How to put text into circle in WPF XAML template?

There are a few ways to do it, like on Centering Text on a WPF Shape
Here's an example:
<Border CornerRadius="50"
Width="60"
Height="60"
Margin="10"
Padding="0,20,0,0"
Background="Aquamarine"
BorderBrush="Black"
BorderThickness="1">
<TextBlock HorizontalAlignment="Center">Test
</TextBlock>
</Border>

Related

get some text inside of border (WPF)

I have a border in my WPF-Application and I want to have some text inside of my border like in my picture below.
But I could not figure out how to do it.
My code right now:
<Border Margin="10" BorderThickness="5px" BorderBrush="Gray" CornerRadius="5" Grid.Column="0" Grid.Row="1">
<RadioButton Margin="5">Test</RadioButton>
</Border>
Thanks for your help!
You could use a GroupBox that meets your needs.
<Grid>
<GroupBox Margin="10">
<GroupBox.Header>
Some Text
</GroupBox.Header>
<TextBlock TextWrapping="WrapWithOverflow" Margin="10" Text="Happy every day!"/>
</GroupBox>
</Grid>

Fit To Window in WPF Mvvm

am new to WPF MVVM, i had an issue with fit to window with zoom in and zoom out
for zoom in and zoom out it is working fine, but on clicking on fit to window content is not setting to actual window height and width. instead there is scrollbar which should not be displayed on fit to window content should be fit to window layout .. is there anything which can help me out.
<!-- Layout display area -->
<dxlc:LayoutItem Focusable="False"
VerticalAlignment="Stretch">
<Grid x:Name="LayoutGrid"
Margin="1">
<dx:ThemedBorder BorderThickness="1"
Margin="5,0,1,2">
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<ContentPresenter Content="{Binding DrawingSurface}"
Height="{Binding CanvasHeight}"
Width="{Binding CanvasWidth}"
VerticalAlignment="Top">
<ContentPresenter.ContextMenu>
<ContextMenu ItemsSource="{Binding WorkingCanvas.ContextMenuItems}" />
</ContentPresenter.ContextMenu>
</ContentPresenter>
<b:Interaction.Triggers>
<b:EventTrigger EventName="SizeChanged">
<b:CallMethodAction MethodName="OnSizeChanged"
TargetObject="{Binding}" />
</b:EventTrigger>
</b:Interaction.Triggers>
</ScrollViewer>
</dx:ThemedBorder>
</Grid>
</dxlc:LayoutItem>

Border that bulges near mouse pointer

I have a ListView populated with ListViewItems, like navigation bar style menu options.
I would like to create the effect of the ListViewItem border "bulging" like in the Mail application on Win10 as shown in this picture
The border "bulges" (fisheye?) as the mouse moves left and right along the ListViewItem. It's a nice effect that I'd like to replicate but am struggling to even get started on how to tackle this.
My list items are bound to a content control which is templated with a ControlTemplate. The ItemsControl ItemTemplate is a DataTemplate containing an image and a Textbox wrapped inside a button control, like this .... (although I suspect how it's created is probably not relevant to my question)
<ContentControl Content="{Binding Path=MenuModel.AllMenuItems}"
x:Name="menuCtrl1"
Template="{StaticResource MenuListItemControlTemplate}"
VerticalAlignment="Top" />
...
<ControlTemplate x:Key="MenuListItemControlTemplate" TargetType="ContentControl">
<Border Background="Transparent" >
<ScrollViewer Margin="{StaticResource DefaultNoMargin}" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{TemplateBinding Content}"
ItemTemplate="{StaticResource MenuListItemDataTemplate}" />
</ScrollViewer>
</Border>
</ControlTemplate>
...
<DataTemplate x:Key="MenuListItemDataTemplate" DataType="local:SingleMenuItem">
<Button Command="{Binding MenuCommand}" Style="{StaticResource MenuButtonStyle}" >
<StackPanel Orientation="Horizontal" >
<Image Source="{Binding MenuIconSource}" Style="{StaticResource MenuItemImage}" />
<TextBox Text="{Binding DisplayText}" Style="{StaticResource MenuItemStyle}" />
</StackPanel>
</Button>
</DataTemplate>
Any tips on how to achieve it or even where to start would be gratefully received.

How can I bind a colorpicker inside a ContextMenu to a label?

I have a custom context menu on my window like so, which contains two color pickers--one for foreground and one for background:
<ContextMenu>
<ContextMenu.Template>
<ControlTemplate>
<Border BorderBrush="Black" BorderThickness="1" Background="White">
<UniformGrid Rows="2">
<Border BorderBrush="Black" BorderThickness="0,0,0,1">
<DockPanel Margin="5">
<Label Content="Background Color" Margin="0,0,10,0" DockPanel.Dock="Left"/>
<xctk:ColorPicker DisplayColorAndName="True" ColorMode="ColorCanvas" SelectedColor="Gray" DockPanel.Dock="Right"/>
</DockPanel>
</Border>
<DockPanel Margin="5">
<Label Content="Foreground Color" Margin="0,0,10,0" DockPanel.Dock="Left"/>
<xctk:ColorPicker Name="cpForegroundColor" DisplayColorAndName="True" ColorMode="ColorCanvas" SelectedColor="White" DockPanel.Dock="Right"/>
</DockPanel>
</UniformGrid>
</Border>
</ControlTemplate>
</ContextMenu.Template>
</ContextMenu>
How exactly could I bind the colorpicker's SelectedColor to a label I have inside the window?
I've attempted using ElementName but I guess this won't work due to differing namescopes. From what I've read it may not be a good idea to bind to things inside a control template as well.
Any suggestions on how (or a better way) to do this would be greatly appreciated--thanks!

Borderless ImageButtons in WrapPanel

I am attempting to create a WrapPanel with seamless ImageButtons containing Artwork. I put together the following ContentTemplate in the hopes that it would provide the seamless look required; however a thin white-line remained around each of the buttons. Can anyone steer me in the right direction?
<Button.ContentTemplate>
<DataTemplate DataType="{x:Type local:ArtInfo}">
<Border Name="border" BorderThickness="0" BorderBrush="blue" Height="280" Width="250" Background="#262c40">
<StackPanel>
<Grid>
<Grid.Resources>
<local:MyConverter x:Key="MyConverter"></local:MyConverter>
<ObjectDataProvider x:Key="Properties.Settings" ObjectType="{x:Type lcl:Properties.Settings}" />
</Grid.Resources>
<Image Name="ArtImage" Margin="10,15,0,0" Height="195" Width="195" VerticalAlignment="Top" >
<Image.Source>
<Binding Path="ArtImage"/>
</Image.Source>
</Image>
</Grid>
<TextBlock Text="{Binding Path=ArtClass}" Margin="10,-17,0,0" FontSize="11" Foreground="white" />
<TextBlock Text="{Binding Path=Student}" Margin="10,0,0,0" FontSize="11" Foreground="white" />
<TextBlock Text="1998" Margin="10,0,0,0" FontSize="11" Foreground="white" />
</StackPanel>
</Border>
</DataTemplate>
</Button.ContentTemplate>
The ContentTemplate tells WPF how to display the content within the Button -- the Button chrome (such as the border and background) remains, and the templated content is displayed within and over that chrome.
You want to replace the entire appearance of the Button, border and all, rather than just customising how its content is displayed. To do this, you need to use the Template property instead. The value of Button.Template is a ControlTemplate rather than a DataTemplate. Within that ControlTemplate, you can use the ContentPresenter to display the "data-templated" content.
In your case, since your DataTemplate is doing all the work, you could get away with a raw ContentPresenter as your template:
<Button.Template>
<ControlTemplate TargetType="Button">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
However, if all your buttons are using the same background, you could move this into the ControlTemplate:
<Button.Template>
<ControlTemplate TargetType="Button">
<Border BorderBrush="Blue" ...>
<ContentPresenter />
</Border>
</ControlTemplate>
</Button.Template>
You could then remove the Border from the DataTemplate. This would really only matter if you were planning to reuse the same Button.Template with other content templates and wanted to keep the appearance of the Button consistent across different kinds of content.
create a usercontrol, put the botton & image in a grid.
<Grid>
<Image Source="icon.png" Panel.ZIndex="1" />
<Button
Panel.ZIndex="2"
FocusVisualStyle="{x:Null}"
Background="Transparent"/>
</Grid>

Resources