CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2009
    Posts
    4

    Exclamation Buttons not updated when window showed or closed

    Hello,

    My application creates multiple windows which are always created, showed and hid/closed when some buttons are pressed. These buttons share this style:

    <Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="ClickMode" Value="Press"></Setter>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type Button}">
    <Grid>
    <Rectangle x:Name="RctBtn" Fill="Blue"/>
    <TextBlock Text="{TemplateBinding Content}"></TextBlock>
    </Grid>
    <ControlTemplate.Triggers>
    <Trigger Property="IsPressed" Value="True">
    <Setter Property="Fill" TargetName="RctBtn" Value="Red" />
    </Trigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>

    My code looks like:

    public Window1()
    {
    InitializeComponent();
    this.button1.AddHandler(Control.MouseDownEvent, new MouseButtonEventHandler(openWindow), true);
    this.button2.AddHandler(Control.MouseDownEvent, new MouseButtonEventHandler(closeWindow), true);
    }

    private void openWindow (object sender, RoutedEventArgs e)
    {
    /* Here some code */
    Window1 w1 = new Window1();

    W1.ShowDialog();
    }

    private void closeWindow (object sender, RoutedEventArgs e)
    {
    This.Close();
    }

    I want to launch this application in a PC with a touch screen, then I’m using MouseDown event instead of Click event.

    I have realized that when these buttons are pressed, sometimes, they are not changed to Red. I tried to call Dispatcher.Invoke with Render priority once the button is pressed but it didn’t solve the problem.

    Object.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
    Application.Current.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);

    ¿Could you help me?

    Thank you in advance,

    iBenzal

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Buttons not updated when window showed or closed

    You mention that you are programming for a touch screen and that you are using the mouse down events. I'm not familiar with programming for a touch screen, so are you saying that Button Click events don't work for touch screens?

  3. #3
    Join Date
    Jul 2009
    Posts
    4

    Re: Buttons not updated when window showed or closed

    Hi Arjay,

    You can use Click events in Touch Screen, but I want that the event fires when the user releases the mouse button. If I use Click, it will fire when a mousedown and mouseup event occur on the same element.

    iBenzal

  4. #4
    Join Date
    Jul 2009
    Posts
    4

    Re: Buttons not updated when window showed or closed

    Hi,

    At the last post, I wrote a mistake: I want that the event fires when mouse button is pressed.

    iBenzal

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Buttons not updated when window showed or closed

    I'm confused. Don't you want an event to fire when a button is pressed? Does it matter if a keyboard, mouse click, or touch screen has pressed the button?

  6. #6
    Join Date
    Jul 2009
    Posts
    4

    Re: Buttons not updated when window showed or closed

    Hi Arjay,

    I want the event fires only when the button is pressed, not released. Moreover, in my program you will only press a button by TouchScreen.

    I hope to have clarified your doubts,

    iBenzal

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured