Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6923963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:36:11+00:00 2026-05-27T10:36:11+00:00

Just spent a few hours trying to get my head around dependency properties (finding

  • 0

Just spent a few hours trying to get my head around dependency properties (finding a lot of valuable info here on the site). I’ve written my very first dependency property, but it is not behaving as I would like it to. Can anybody have a look at my code and see if he/she can spot whats wrong?
When trying to run the app I get a TargetInvocationException was thrown

  <Window x:Class="TextEditorMVVM.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:TextEditorMVVM.ViewModel"
    Title="MainWindow" Height="660" Width="621" ResizeMode="CanResize" Background="Gray">
<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Resources/Dictionary1.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <c:TextEditorViewModel x:Key="TextEditorViewModel"></c:TextEditorViewModel>
    </ResourceDictionary> 
</Window.Resources>
<Border CornerRadius="10" BorderThickness="12" Background="#FF505050">
    <Border.BorderBrush>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="LightGray" Offset="1" />
            <GradientStop Color="Gray" Offset="0" />
        </LinearGradientBrush>
    </Border.BorderBrush>
    <StackPanel DataContext="{StaticResource TextEditorViewModel}">
    <Menu Height="auto" Background="Transparent" Foreground="White">
        <MenuItem Width=" auto" Height="auto" Header="_File" VerticalAlignment="Center">
            <MenuItem Header="_New" Command="{Binding CreateNewTabCommand}"></MenuItem>
            <MenuItem Header="_Open" Command="{Binding OpenFileCommand}"></MenuItem>
            <MenuItem Header="_Save" Command="{Binding SaveFileCommand}"></MenuItem>
            <MenuItem Header="_Close" Command="{Binding CloseTabCommand}"></MenuItem>
            <MenuItem Header="_Print" Command="{Binding PrintCommand}"></MenuItem>
            <MenuItem Header="_Exit" Command="{Binding }"></MenuItem>
        </MenuItem>
        <MenuItem Width=" auto" Height="auto" Header="_Edit" VerticalAlignment="Center">
            <MenuItem Header="_Cut" Command="ApplicationCommands.Cut"></MenuItem>
            <MenuItem Header="_Copy" Command="ApplicationCommands.Copy"></MenuItem>
            <MenuItem Header="_Paste" Command="ApplicationCommands.Paste"></MenuItem>
        </MenuItem>
        <MenuItem Width=" auto" Height="auto" Header="_Help" VerticalAlignment="Center">
            <MenuItem Header="_Call Mikael" Command="{Binding }"></MenuItem>
            <MenuItem Header="_Call Semyon" Command="{Binding }"></MenuItem>
            <MenuItem Header="_Cry" Command="{Binding }"></MenuItem>
        </MenuItem>
        <Expander Header="Autosave" VerticalAlignment="Center" Foreground="White">
            <StackPanel Orientation="Horizontal">
                <CheckBox VerticalAlignment="Center" IsChecked="{Binding IsChecked, Mode=TwoWay}"></CheckBox>
                <TextBox Width="40" Height="20" Margin="4" ></TextBox>
                    <Label VerticalAlignment="Center" Foreground="White">seconds</Label>
            </StackPanel>
        </Expander>
    </Menu>
        <c:TransparentTb IsTransparent="False" Text="Why aren't you working????">
        </c:TransparentTb>
    <TabControl x:Name="_tabControl" ItemsSource="{Binding TestTab}" SelectedItem="{Binding SelectedTab}" Background="Transparent" BorderThickness="0">
        <TabControl.ItemContainerStyle>
            <Style TargetType="TabItem">
                <Setter Property="Header" Value="{Binding Title}"/>
                    <Setter Property="Style" Value="Transparent"/>
                    <Setter Property="Content" Value="{Binding InputText}"/>
                </Style>
        </TabControl.ItemContainerStyle>
    </TabControl>
</StackPanel>
</Border>

class TransparentTb : TextBlock
{
    static TransparentTb()
    {

    }


    {
        get { return (bool) GetValue(IsTranparentProperty); }
        set { SetValue(IsTranparentProperty, value); }
    }

    // Using a DependencyProperty as the backing store for IsTranparent.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty IsTranparentProperty =
        DependencyProperty.Register("IsTransparent", typeof (bool), typeof (TransparentTb),
                                    new UIPropertyMetadata(false, TransparentTb.IsTransparentPropertyChanged,
                                                           TransparentTb.IsTransparentCoerce, false)); 


    private static void IsTransparentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        TransparentTb inst = (TransparentTb) d;

        if ((bool)e.NewValue == true)
        {
            inst.Background = Brushes.Transparent;
        }
        else inst.Background = Brushes.Black;
    }

    private static object IsTransparentCoerce(DependencyObject d, object value)
    {
        return value;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:36:12+00:00Added an answer on May 27, 2026 at 10:36 am

    Changing this line of Xaml… < Setter Property=”Style” Value=”Transparent”/>

    To this…

    <!-- <Setter Property="Style" Value="Transparent"/> -->
    

    (i.e., comment it out)

    Will avoid the exception.

    Setting a style the way you are doing would entail referencing something already defined in the object tree like {StaticResource Transparent}.

    The inner exception is ‘object reference not set…’, which makes it clear that the constructor cannot find a reference to “Transparent” the way it has been coded. Note that the exception is thrown after the TransparentTb is already constructed. You can prove this by setting breakpoints.

    Also, I checked your TransparentTb code, and it works fine. The culprit is your TabItem Style Setter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just spent a few hours pulling my hair out over this. I'm trying
So I just spent the last few hours pouring over code trying to figure
I would not say I wasted my time, but spent around few hours changing
I would not say I wasted my time, but spent around few hours changing
I've spent a few hours playing around with this one, without success so far.
spent a few hours trying to figure this out, but cannot for the life
It sounds so simple... I spent a few hours just getting the first part
I spent hours on this and I just cannot get it: What I am
I just spent way too long trying to diagnose why, in the following snippet
I just spent 5 hours by checking Google gadgets websites and FAQs, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.