FAQ Database Discussion Community

WPF C# Set “ContentPresenter.Foreground” by code

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

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...

Presenting an ItemsControl

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

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

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...

Stange behavior of 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...