2

Im developing a WPF Application with a TabControl. Inside the TabItems of this TabControl I have implemented EventTriggers which react on a LeftButtonMouseDownEvent to do some stuff. My Problem is that during Design Time of Visual Studio the Event is triggered and it seems to block any further interactions in the Design Window.

Is there a possibility to ignore the trigger, when my Visual Studio is in Design Time. I would prefer to do this in pure XAML. I know that there exists the "mc:Ignorable" tag, but I want it the other way round. If needed i posted a Code Snippet for you.

Thanks for your help!

<TabItem>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonDown">
            <SomeAction/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TabItem>
Febertson
  • 398
  • 4
  • 23

2 Answers2

0

I don't know how to do it in xaml, but, may be, adding to code SomeAction this, will resolve your problem.

var isInDesignMode = DesignerProperties.GetIsInDesignMode(new DependencyObject());
if(isInDesignMode)
{
    // using in VisualStudio or Blend
}
else
{
    // using in application
}
  • 1
    This doesn't help me much, because i dont want to handle my Actions in Code. Those are Actions i have no influence on, they must be called directly in Xaml. And I'm not a big fan of attaching these Triggers/Actions in Code Behind. – Febertson Dec 15 '17 at 10:09
  • Have you seen the [question](https://stackoverflow.com/questions/2764415/how-to-give-the-condition-for-eventtrigger)? – Alex Roy Dec 15 '17 at 12:08
  • 1
    Thanks for showing me the question, but I dont think its the same Problem as I have. It's close but i think the main difference is that his problem is during the runtime and mine is in the designer. And i dont want to write some Conditon-Bindings that will work in Design Time but might break my XAML while in Runtime (On some weird occasions that I cannot predict yet). – Febertson Dec 18 '17 at 07:32
0

Try extending mc:Ignorable with i for your case, i.e. mc:Ignorable="d i":

<UserControl ...
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             ...
             d:DesignHeight="600"
             d:DesignWidth="800"
             ...
             mc:Ignorable="d i">

...

<TabItem>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeftButtonDown">
            <SomeAction/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TabItem>

...

</UserControl>
Sevenate
  • 6,221
  • 3
  • 49
  • 75