Click here to Skip to main content
13,086,228 members (71,339 online)

Silverlight / WPF

QuestionDataTrigger bind to a Property Pin
mbv80023-Dec-12 17:01
membermbv80023-Dec-12 17:01 
I am trying to change the appearance of a control when the value of a property changes. I am using the XAML and C# code below, but nothing happens when I click on the button that changes the value of the Property myProperty, except when I first run the application. Any suggestions?

<Window x:Class="WpfApplication3.MainWindow"
        Title="MainWindow" Height="350" Width="525">
<Button Height="34" HorizontalAlignment="Left" x:Name="toggleBroadcast" VerticalAlignment="Top" Width="133" Margin="180,0,0,0">
  <Style x:Name="bb" TargetType="{x:Type Button}">
   <Setter Property="Content" Value="Original Content"/>
      <DataTrigger Binding="{Binding Path=myProperty}" Value="true">
        <Setter Property="Content" Value="IS TRUE"/>
      <DataTrigger Binding="{Binding Path=myProperty}" Value="false">
          <Setter Property="Content" Value="IS FALSE"/>
        <Button Content="Click on This Button" HorizontalAlignment="Left" Width="158" Click="Button_Click_1" Height="34" VerticalAlignment="Top"/>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication3
    public partial class MainWindow : Window
        Boolean _Check = false;
        public MainWindow()
            DataContext = this;
        public Boolean check
                return _Check;
        private void Button_Click_1(object sender, RoutedEventArgs e)
            _Check = !_Check;

AnswerRe: DataTrigger bind to a Property Pin
Pete O'Hanlon23-Dec-12 19:17
protectorPete O'Hanlon23-Dec-12 19:17 
AnswerRe: DataTrigger bind to a Property Pin
Wayne Gaylard23-Dec-12 19:39
mentorWayne Gaylard23-Dec-12 19:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 12 Aug 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid