I'm reasonably new to C# and even newer to WPF projects in C#, i'm having a lot of trouble getting to grips with how to use the template property and its doing m head in. Firstly an explanation of what I am trying to achieve:
I am working on a very large project and thought it would be tidy to have any templated types (for visual styles) stored in an external dll (for reusabilities sake), the first thing I have come to that I would like for a visual style is a transparent button (setting borderbrush and background to transparent still leaves a strange chrome effect behind the button (tedious)).
I have tried following various guides on the internet but am now getting a vague error (Cannot unset a Setter value) of which there is documentation.
I really do need to get to grips (especially with the visual aspect) as quick as possible.
The solution I would prefer but dont think is possible would be to just say display the button as a label with transparent background and border (while still keeping the button events) but after looking at a post on another website it made it seem like this was not possible.

Any help would be greatly appreciated,



6 Years
Discussion Span
Last Post by hotchkissChris

Show us your code please.

        <ControlTemplate x:Key="ts"  TargetType="{x:Type Button}" >
            <Border Name="tt" CornerRadius="4"  Focusable="True"  Background="Transparent" HorizontalAlignment="Center" Padding="3" Margin="5" BorderBrush="Black" BorderThickness="2">
                <ContentPresenter />
                <Trigger Property="Control.IsMouseOver" Value="True">
                    <Setter TargetName="tt" Property="Background" Value="Red"/>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
            <ImageBrush  ImageSource="Images/1.jpg" TileMode="Tile" Viewbox="0,0,.3,.4"/>
        <Button Template="{StaticResource ts}" 
        <Button Template="{StaticResource ts}">Test</Button>

Hi, thanks for the response, the way i've been try to use it is as follows:

one dll that contains an xaml file with the following
dll is called DisplayTemplates and xaml file is called transparentbutton.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    <Style x:Key="TransparentButton" TargetType="Button">
        <Setter Property="Template">
                    <ControlTemplate TargetType="Button">
                        <StackPanel Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" x:Name="panel">
                            <ContentPresenter Width="{TemplateBinding Width}" Height="{TemplateBinding Width}" />
                            <Trigger Property="IsPressed" Value="true">
                                <Setter Property="Background" Value="Transparent" TargetName="panel" />
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Background" Value="Transparent" />


(although as you can see this is where i'm struggling, as i don't really understand the template concept yet)

and then using in another file as follows

<Window x:Class="MessageDisplay.message_display_window"
    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    Title="Error" Height="262" Width="602" FontFamily="Verdana" IsTabStop="True" TabIndex="1" ResizeMode="NoResize" Loaded="Window_Loaded">
        <ResourceDictionary Source="pack://application:,,,/DisplayTemplates;component/transparentbutton.xaml"/>
    <Grid Visibility="Visible">
        <Label Margin="12,12,10,0" Name="lbl_ErrorDescription" BorderBrush="DarkGray" BorderThickness="2" Height="148" VerticalAlignment="Top"></Label>
        <ListView Height="88" Width="558"  Margin="12,182,10,0" Name="lsv_ErrorDetails" BorderBrush="DarkGray" BorderThickness="2" VerticalAlignment="Top" Visibility="Hidden" ItemsSource="{Binding ErrorCollection}">
                    <GridViewColumn Width="30" Header="Name"
                        DisplayMemberBinding="{Binding ErrorName}"  />
                    <GridViewColumn Width="140" Header="Details"  
                        DisplayMemberBinding="{Binding ErrorDetail}" />
        <Label Height="22" Margin="12,160,192,44" Name="lbl_TimeOfError" VerticalAlignment="Top">Time Of Error:</Label>
        <Button Height="22" HorizontalAlignment="Right" HorizontalContentAlignment="Right"  Margin="0,160,10,0" Name="btn_ShowDetails" VerticalAlignment="Top" Width="130" Foreground="Blue" Cursor="Hand" Focusable="True" IsTabStop="True" TabIndex="1" Click="btn_ShowDetails_Click" Style="{StaticResource TransparentButton}">Show details...</Button>
        <Button Height="34" Margin="230,0,228,5" Name="btn_Ok" VerticalAlignment="Bottom" Click="btn_Ok_Click">Ok</Button>



This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.