1

I have an application that has 2 versions and 2 databases. One is the real deal and the other is a test version so that the users can test stuff before they apply it on the real app. I need to apply a style to all windows if the the user in the test mode so the users can differentiate when the have both versions open. what I tried to do so far is that I created the style I want which is a simple border thickness and border brush setters and created a property in the Application file and set it to true on start up if the version is the test version. the code looks like this now.

Application.xaml:

 <Style TargetType="{x:Type Window}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsTestVersion}" Value="True">
                    <Setter Property="BorderThickness" Value="3" />
                    <Setter Property="BorderBrush" Value="Red" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

Application.xaml.vb:

 Private _isTestVersion As Boolean = False
Public Property IsTestVersion() As Boolean
    Get
        Return _isTestVersion
    End Get
    Set(ByVal value As Boolean)
        _isTestVersion = value
    End Set
End Property

Protected Overrides Sub OnStartup(e As System.Windows.StartupEventArgs)
    MyBase.OnStartup(e)
    ' some irrelevant code 

    ' checking if the current version is the test version
    If My.Settings.b2ConnectionString.IndexOf("\dev;") > 0 Then
        IsTestVersion = True

    End If
End Sub

this obviously isn't working and i don't want to write code in every single window in the application. Is there a way solve this ?

EDIT:

applying the style is not the problem, the code below works as I want it to, what seems to be the problem is that the trigger isn't working

 <Style TargetType="{x:Type Window}">
 <Setter Property="BorderThickness" Value="3" />
 <Setter Property="BorderBrush" Value="Red" />
</Style>
Mohamad Hammash
  • 237
  • 1
  • 8
  • Bad news for you - it's hard to apply style to all windows in application. Check this thread: https://stackoverflow.com/questions/431940/how-to-set-default-wpf-window-style-in-app-xaml – Quercus Jan 31 '22 at 10:55
  • applying the style wasn't a problem ` ` this works perfectly fine the problem is that the triggers are not working – Mohamad Hammash Jan 31 '22 at 12:27

0 Answers0