Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Trigger problems [modified]

Trigger problems [modified]

Scheduled Pinned Locked Moved WPF
wpfcsharpcssdatabasecom
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GDavy
    wrote on last edited by
    #1

    ---modified. Original problem with this is solved, but I got a new problem with the same xaml --- Ok I just started in WPF so it might be very obvious. I made a UserControl which contains also a ToggleButton, when that togglebutton is pressed I want to alter the background of the border control.

    <UserControl x:Class="StoreDBViewer.MyTableControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >
    <Grid>
    <Border x:Name="MyCtrlBorder" BorderThickness="1" BorderBrush="Gray" Background="Green">

          <!-- Here a bunch of controls and stuff is added -->
          <ToggleButton x:Name="btnToggle" Margin="5,5" Click="OnToggleColView">
             Button text
          </ToggleButton>
      </Border>
    </Grid>
    **<UserControl.Triggers>
      <Trigger SourceName="btnToggle" Property="ToggleButton.IsChecked" Value="True">
        <Setter TargetName="MyCtrlBorder" Property="Border.Background" Value="Blue" />
      </Trigger>
    </UserControl.Triggers>**
    

    </UserControl>

    This compiles correctly, but as soon as I run the app an exception is thrown( the exception is not thrown if I comment out the Trigger part). Does anyone know what might be wrong here? Regards, Davy

    modified on Monday, June 30, 2008 8:55 AM

    G 1 Reply Last reply
    0
    • G GDavy

      ---modified. Original problem with this is solved, but I got a new problem with the same xaml --- Ok I just started in WPF so it might be very obvious. I made a UserControl which contains also a ToggleButton, when that togglebutton is pressed I want to alter the background of the border control.

      <UserControl x:Class="StoreDBViewer.MyTableControl"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      >
      <Grid>
      <Border x:Name="MyCtrlBorder" BorderThickness="1" BorderBrush="Gray" Background="Green">

            <!-- Here a bunch of controls and stuff is added -->
            <ToggleButton x:Name="btnToggle" Margin="5,5" Click="OnToggleColView">
               Button text
            </ToggleButton>
        </Border>
      </Grid>
      **<UserControl.Triggers>
        <Trigger SourceName="btnToggle" Property="ToggleButton.IsChecked" Value="True">
          <Setter TargetName="MyCtrlBorder" Property="Border.Background" Value="Blue" />
        </Trigger>
      </UserControl.Triggers>**
      

      </UserControl>

      This compiles correctly, but as soon as I run the app an exception is thrown( the exception is not thrown if I comment out the Trigger part). Does anyone know what might be wrong here? Regards, Davy

      modified on Monday, June 30, 2008 8:55 AM

      G Offline
      G Offline
      Gideon Engelberth
      wrote on last edited by
      #2

      What is the error message of the exception (or the message of the InnerException, or the InnerException of the InnerException, or however many levels it takes to find something useful)? In cases like this, the error messages usually have a good pointer for where to start looking.

      G 1 Reply Last reply
      0
      • G Gideon Engelberth

        What is the error message of the exception (or the message of the InnerException, or the InnerException of the InnerException, or however many levels it takes to find something useful)? In cases like this, the error messages usually have a good pointer for where to start looking.

        G Offline
        G Offline
        GDavy
        wrote on last edited by
        #3

        Thanks for the reply. The message of the exception itself was pretty useless, but following the innerexceptions 3 levels up I came to this message: Triggers collection members must be of type EventTrigger. So doing some research on that I found that this kind of trigger only works in ControlTemplate,DataTemplates and Style... So I guess I have to reorder some stuff in the xaml file to fit the triggers somewhere in a style or so. Regards, Davy

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups