Contentcontrol not updating Text











up vote
0
down vote

favorite












I have a View that contains a lot of input parameters. Each parameter consists of a label (name of the parameter) a textbox for its value and another label for its units (eg. kNm).



The Control displays in a horizontal Stackpanel.



When changing the Text (ToWay Binding) of the Textbox the underlying Property (eg. DesignLife) does not update anymore, since I switched from straight WPF (OnPropertyChanged) to MVVM Light (RaisePropertyChanged).



Here are some relevant pieces of code:



using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace xxxx.Views.CustomControls
{
public class InputParameter : ContentControl
{
static InputParameter()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(InputParameter), new FrameworkPropertyMetadata(typeof(InputParameter)));
}

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
// some properties left out
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(InputParameter));
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

}
}

<UserControl
x:Class="xxxx.Views.MainUserControls.Column"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:xxxx.Views.CustomControls"
xmlns:cf="clr-namespace:xxxx.Model.Config"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tt="clr-namespace:xxxx.Properties"
DataContext="{Binding Main.Calc, Source={StaticResource Locator}}"
mc:Ignorable="d">
<GroupBox Margin="3">

<StackPanel Orientation="Vertical">

<!-- Stuff left out -->

<cc:InputParameter
NameContent="Design life"
Text="{Binding DesignLife, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat=N0}"
UnitContent="years" />
<!-- Stuff left out -->

</StackPanel>
</GroupBox>
</UserControl>

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:CoCa.Views.CustomControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style x:Key="InputParm" TargetType="{x:Type cc:InputParameter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type cc:InputParameter}">
<StackPanel Style="{StaticResource SPanel}">

<Label
x:Name="PART_NameLabel"
Width="130"
HorizontalContentAlignment="Left"
Content="{TemplateBinding NameContent}"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource LabelStyle1}"
ToolTip="{TemplateBinding ToolTip}" />
<TextBox
x:Name="PART_TextBox"
Width="70"
Background="{TemplateBinding TbBackground}"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource Tb}"
Text="{TemplateBinding Property=Text}" />
<Label
x:Name="PART_UnitLabel"
Content="{TemplateBinding UnitContent}"
Foreground="{Binding ElementName=PART_NameLabel, Path=Foreground}"
Style="{StaticResource Unit}" />

</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

private int _designLife;
public int DesignLife
{
get => _designLife;

set
{
Set<int>(() => DesignLife, ref _designLife, value, true);
}
}


I suspect that RaisePropertyChanged does not get called because it is not used anywhere in the class InputParameter's Text DependencyProperty. (Maybe under the hood it does?)



Questions:



1: Is the way I made InputParameter the way to go?



2: Is my suspicion correct?



3 a: If so, How do I get RaisePropertyChanged called?



b: If not: what could be the problem?










share|improve this question
























  • In the Binding, try adding UpdateSourceTrigger=PropertyChanged to trigger the binding whenever the text changes and not only when the `TextBox' is losing focus.
    – TomerAgmon1
    Nov 18 at 9:11










  • Huh? Which binding? a templatebinding does not allow an UpdateSourceTrigger, and the cc:InputParameter already has one...
    – Erik
    Nov 19 at 15:23










  • Oh you're right. Well, it's definitely not the reason you suspect
    – TomerAgmon1
    Nov 21 at 8:04















up vote
0
down vote

favorite












I have a View that contains a lot of input parameters. Each parameter consists of a label (name of the parameter) a textbox for its value and another label for its units (eg. kNm).



The Control displays in a horizontal Stackpanel.



When changing the Text (ToWay Binding) of the Textbox the underlying Property (eg. DesignLife) does not update anymore, since I switched from straight WPF (OnPropertyChanged) to MVVM Light (RaisePropertyChanged).



Here are some relevant pieces of code:



using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace xxxx.Views.CustomControls
{
public class InputParameter : ContentControl
{
static InputParameter()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(InputParameter), new FrameworkPropertyMetadata(typeof(InputParameter)));
}

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
// some properties left out
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(InputParameter));
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

}
}

<UserControl
x:Class="xxxx.Views.MainUserControls.Column"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:xxxx.Views.CustomControls"
xmlns:cf="clr-namespace:xxxx.Model.Config"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tt="clr-namespace:xxxx.Properties"
DataContext="{Binding Main.Calc, Source={StaticResource Locator}}"
mc:Ignorable="d">
<GroupBox Margin="3">

<StackPanel Orientation="Vertical">

<!-- Stuff left out -->

<cc:InputParameter
NameContent="Design life"
Text="{Binding DesignLife, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat=N0}"
UnitContent="years" />
<!-- Stuff left out -->

</StackPanel>
</GroupBox>
</UserControl>

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:CoCa.Views.CustomControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style x:Key="InputParm" TargetType="{x:Type cc:InputParameter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type cc:InputParameter}">
<StackPanel Style="{StaticResource SPanel}">

<Label
x:Name="PART_NameLabel"
Width="130"
HorizontalContentAlignment="Left"
Content="{TemplateBinding NameContent}"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource LabelStyle1}"
ToolTip="{TemplateBinding ToolTip}" />
<TextBox
x:Name="PART_TextBox"
Width="70"
Background="{TemplateBinding TbBackground}"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource Tb}"
Text="{TemplateBinding Property=Text}" />
<Label
x:Name="PART_UnitLabel"
Content="{TemplateBinding UnitContent}"
Foreground="{Binding ElementName=PART_NameLabel, Path=Foreground}"
Style="{StaticResource Unit}" />

</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

private int _designLife;
public int DesignLife
{
get => _designLife;

set
{
Set<int>(() => DesignLife, ref _designLife, value, true);
}
}


I suspect that RaisePropertyChanged does not get called because it is not used anywhere in the class InputParameter's Text DependencyProperty. (Maybe under the hood it does?)



Questions:



1: Is the way I made InputParameter the way to go?



2: Is my suspicion correct?



3 a: If so, How do I get RaisePropertyChanged called?



b: If not: what could be the problem?










share|improve this question
























  • In the Binding, try adding UpdateSourceTrigger=PropertyChanged to trigger the binding whenever the text changes and not only when the `TextBox' is losing focus.
    – TomerAgmon1
    Nov 18 at 9:11










  • Huh? Which binding? a templatebinding does not allow an UpdateSourceTrigger, and the cc:InputParameter already has one...
    – Erik
    Nov 19 at 15:23










  • Oh you're right. Well, it's definitely not the reason you suspect
    – TomerAgmon1
    Nov 21 at 8:04













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a View that contains a lot of input parameters. Each parameter consists of a label (name of the parameter) a textbox for its value and another label for its units (eg. kNm).



The Control displays in a horizontal Stackpanel.



When changing the Text (ToWay Binding) of the Textbox the underlying Property (eg. DesignLife) does not update anymore, since I switched from straight WPF (OnPropertyChanged) to MVVM Light (RaisePropertyChanged).



Here are some relevant pieces of code:



using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace xxxx.Views.CustomControls
{
public class InputParameter : ContentControl
{
static InputParameter()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(InputParameter), new FrameworkPropertyMetadata(typeof(InputParameter)));
}

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
// some properties left out
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(InputParameter));
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

}
}

<UserControl
x:Class="xxxx.Views.MainUserControls.Column"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:xxxx.Views.CustomControls"
xmlns:cf="clr-namespace:xxxx.Model.Config"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tt="clr-namespace:xxxx.Properties"
DataContext="{Binding Main.Calc, Source={StaticResource Locator}}"
mc:Ignorable="d">
<GroupBox Margin="3">

<StackPanel Orientation="Vertical">

<!-- Stuff left out -->

<cc:InputParameter
NameContent="Design life"
Text="{Binding DesignLife, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat=N0}"
UnitContent="years" />
<!-- Stuff left out -->

</StackPanel>
</GroupBox>
</UserControl>

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:CoCa.Views.CustomControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style x:Key="InputParm" TargetType="{x:Type cc:InputParameter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type cc:InputParameter}">
<StackPanel Style="{StaticResource SPanel}">

<Label
x:Name="PART_NameLabel"
Width="130"
HorizontalContentAlignment="Left"
Content="{TemplateBinding NameContent}"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource LabelStyle1}"
ToolTip="{TemplateBinding ToolTip}" />
<TextBox
x:Name="PART_TextBox"
Width="70"
Background="{TemplateBinding TbBackground}"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource Tb}"
Text="{TemplateBinding Property=Text}" />
<Label
x:Name="PART_UnitLabel"
Content="{TemplateBinding UnitContent}"
Foreground="{Binding ElementName=PART_NameLabel, Path=Foreground}"
Style="{StaticResource Unit}" />

</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

private int _designLife;
public int DesignLife
{
get => _designLife;

set
{
Set<int>(() => DesignLife, ref _designLife, value, true);
}
}


I suspect that RaisePropertyChanged does not get called because it is not used anywhere in the class InputParameter's Text DependencyProperty. (Maybe under the hood it does?)



Questions:



1: Is the way I made InputParameter the way to go?



2: Is my suspicion correct?



3 a: If so, How do I get RaisePropertyChanged called?



b: If not: what could be the problem?










share|improve this question















I have a View that contains a lot of input parameters. Each parameter consists of a label (name of the parameter) a textbox for its value and another label for its units (eg. kNm).



The Control displays in a horizontal Stackpanel.



When changing the Text (ToWay Binding) of the Textbox the underlying Property (eg. DesignLife) does not update anymore, since I switched from straight WPF (OnPropertyChanged) to MVVM Light (RaisePropertyChanged).



Here are some relevant pieces of code:



using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace xxxx.Views.CustomControls
{
public class InputParameter : ContentControl
{
static InputParameter()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(InputParameter), new FrameworkPropertyMetadata(typeof(InputParameter)));
}

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
// some properties left out
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(InputParameter));
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}

}
}

<UserControl
x:Class="xxxx.Views.MainUserControls.Column"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:xxxx.Views.CustomControls"
xmlns:cf="clr-namespace:xxxx.Model.Config"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tt="clr-namespace:xxxx.Properties"
DataContext="{Binding Main.Calc, Source={StaticResource Locator}}"
mc:Ignorable="d">
<GroupBox Margin="3">

<StackPanel Orientation="Vertical">

<!-- Stuff left out -->

<cc:InputParameter
NameContent="Design life"
Text="{Binding DesignLife, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat=N0}"
UnitContent="years" />
<!-- Stuff left out -->

</StackPanel>
</GroupBox>
</UserControl>

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:CoCa.Views.CustomControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Style x:Key="InputParm" TargetType="{x:Type cc:InputParameter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type cc:InputParameter}">
<StackPanel Style="{StaticResource SPanel}">

<Label
x:Name="PART_NameLabel"
Width="130"
HorizontalContentAlignment="Left"
Content="{TemplateBinding NameContent}"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource LabelStyle1}"
ToolTip="{TemplateBinding ToolTip}" />
<TextBox
x:Name="PART_TextBox"
Width="70"
Background="{TemplateBinding TbBackground}"
Foreground="{TemplateBinding Foreground}"
Style="{StaticResource Tb}"
Text="{TemplateBinding Property=Text}" />
<Label
x:Name="PART_UnitLabel"
Content="{TemplateBinding UnitContent}"
Foreground="{Binding ElementName=PART_NameLabel, Path=Foreground}"
Style="{StaticResource Unit}" />

</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

private int _designLife;
public int DesignLife
{
get => _designLife;

set
{
Set<int>(() => DesignLife, ref _designLife, value, true);
}
}


I suspect that RaisePropertyChanged does not get called because it is not used anywhere in the class InputParameter's Text DependencyProperty. (Maybe under the hood it does?)



Questions:



1: Is the way I made InputParameter the way to go?



2: Is my suspicion correct?



3 a: If so, How do I get RaisePropertyChanged called?



b: If not: what could be the problem?







xaml mvvm-light contentcontrol






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 15:31

























asked Nov 17 at 13:02









Erik

372416




372416












  • In the Binding, try adding UpdateSourceTrigger=PropertyChanged to trigger the binding whenever the text changes and not only when the `TextBox' is losing focus.
    – TomerAgmon1
    Nov 18 at 9:11










  • Huh? Which binding? a templatebinding does not allow an UpdateSourceTrigger, and the cc:InputParameter already has one...
    – Erik
    Nov 19 at 15:23










  • Oh you're right. Well, it's definitely not the reason you suspect
    – TomerAgmon1
    Nov 21 at 8:04


















  • In the Binding, try adding UpdateSourceTrigger=PropertyChanged to trigger the binding whenever the text changes and not only when the `TextBox' is losing focus.
    – TomerAgmon1
    Nov 18 at 9:11










  • Huh? Which binding? a templatebinding does not allow an UpdateSourceTrigger, and the cc:InputParameter already has one...
    – Erik
    Nov 19 at 15:23










  • Oh you're right. Well, it's definitely not the reason you suspect
    – TomerAgmon1
    Nov 21 at 8:04
















In the Binding, try adding UpdateSourceTrigger=PropertyChanged to trigger the binding whenever the text changes and not only when the `TextBox' is losing focus.
– TomerAgmon1
Nov 18 at 9:11




In the Binding, try adding UpdateSourceTrigger=PropertyChanged to trigger the binding whenever the text changes and not only when the `TextBox' is losing focus.
– TomerAgmon1
Nov 18 at 9:11












Huh? Which binding? a templatebinding does not allow an UpdateSourceTrigger, and the cc:InputParameter already has one...
– Erik
Nov 19 at 15:23




Huh? Which binding? a templatebinding does not allow an UpdateSourceTrigger, and the cc:InputParameter already has one...
– Erik
Nov 19 at 15:23












Oh you're right. Well, it's definitely not the reason you suspect
– TomerAgmon1
Nov 21 at 8:04




Oh you're right. Well, it's definitely not the reason you suspect
– TomerAgmon1
Nov 21 at 8:04

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351506%2fcontentcontrol-not-updating-text%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53351506%2fcontentcontrol-not-updating-text%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga