Click here to Skip to main content
Sign Up to vote bad
good
See more: C#WPFC#4.0
I've edited a template from a Button, then I added an Text into it without defining its "Content" property.

Style :
<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:appStyles="clr-namespace:MyWin" x:Class="MyWin.WinEvent">
        <Style x:Key="WindowStyle1" TargetType="{x:Type Window}" >
                <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Border Name="Border1">
                        <Grid >
                            <Button DataContext="{x:Type appStyles:WinEvent}" Content="{Binding _Static}" Name="ButtonClick" HorizontalAlignment="Stretch" Height="51.443" Margin="1,0,0,0" VerticalAlignment="Top" Width="Auto">
                        </Grid>
                    </Border>
               </ControlTemplate>
            </Setter.Value>
         </Setter>
         <EventSetter Event="Loaded" Handler="Load"/>
     </style>
</ResourceDictionary>
 

C# :
namespace MyWin
{
	partial class WinEvent
	{
 
        private string _Static;
        public string State
        {
            get { return _Static; }
            set
            {
                if (value != _Static)
                {
                    _Static = value;
                }
            }
        }
 
        private void Load(object sender, EventArgs e)
        {
            
            State = "Click";
        }
 
    }
}
 
Thank you.
Posted 15 Jun '12 - 20:20
Edited 15 Jun '12 - 20:47

Comments
Sandeep Mewara - 16 Jun '12 - 4:28
And the issue....?
SteveAdey - 20 Jun '12 - 16:43
I'd read some more books on WPF.
Wes Aday - 22 Jun '12 - 15:47
Was there a question here and I missed it?

1 solution

If I understand your question, I think what you need to do in create a new class that inherits from Button, and add a dependencyproperty(s) (or propety if do not need all the bells and whistles) for the value. Should be really easy.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,356
1 OriginalGriff 6,571
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 22 Jun 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid