FAQ Database Discussion Community


WPF C# Set “ContentPresenter.Foreground” by code

c#,wpf,foreground,contentpresenter
I could only find xaml specifiy solutions to this problem using TextElement.Foreground="...". But I'd like to set the Foreground of a ContentPresenter in C#. Can you tell me how that works? Thank you very much!

How to center Content in a Button Template and keep mouse events in empty area

c#,wpf,button,controltemplate,contentpresenter
I am using a Button Template to customize the look and feel of my buttons like so: <ControlTemplate TargetType="Button"> <Border x:Name="Border" CornerRadius="6" BorderThickness="1"> <ContentPresenter Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" ContentSource="Content"/> </Border> </ControlTemplate> I want to center horizontally and vertically the Content, but when I do it the "empty" areas of the...

Stange behavior of ContentPresenter

c#,wpf,xaml,templates,contentpresenter
I was just playing around with a simple ContentPresenter. <TextBox Text="{Binding Path=TestString, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/> <ContentPresenter Content="{Binding}"> <ContentPresenter.ContentTemplate> <DataTemplate> <StackPanel> <TextBox Text="{Binding Path=TestString, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/> </StackPanel> </DataTemplate> </ContentPresenter.ContentTemplate> </ContentPresenter> This code works perfectly - if I enter...

Presenting an ItemsControl

wpf,xaml,contentpresenter
simple question! I want to present an itemscontrol inside of an expander and grid which contains a textbox. I want to do this multiple times so I wrapped it in a ControlTemplate. <ControlTemplate x:Key="ArrayPresenter"> <Expander Template="{StaticResource ArrayTemplate}"> <Grid> <ContentPresenter/> <TextBlock FontWeight="Bold" Text="Empty" Margin="3" HorizontalAlignment="Center" Foreground="#66C9C9C9" FontSize="15" Visibility="{quickConverter:Binding '$P.Count == 0...

Set the ContentPresenter's content color, when the content is not a text

wpf,xaml,contentcontrol,contentpresenter
Let's say that My ContentPresenter contains a Viewbox with Paths inside instead of some text, how do I change the Color of those Paths from the Content Presenter Example I have this ResourceDictionary : <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Viewbox> <Grid> <Grid Name="backgroundGrid" Width="48" Height="48" Visibility="Collapsed" /> <Path Data="M19.833,0L32.5,0 32.5,19.833999 52.334,19.833999 52.334,32.500999...

ContentPresenter in ItemControl.ItemTemplate to show displaymemberpath of itemscontrol

c#,wpf,itemscontrol,contentpresenter
I want to know is there anyway to put contentpresenter in itemtemplate of an itemscontrol to display my data. I don't want hard code binding like Text="{Binding username}" cause I am building a custom control, I think ContentPresenter is what I want. But after I tried using contentpresenter, it give...