Reputation: 25
I'm working on my first Windows Phone 7 App and have the problem that a binding on a textbox don't work and i really don't know why. Other bindings works perfect.
If the Date is changed, the text in the textbox should also be changed.
Xaml:
<TextBlock x:Name="ZodiacText" Text="{Binding Path=ZodiacString, Mode=OneWay}" FontSize="20" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
And the code behind:
public DateTime Date
{
get { return date; }
set
{
if (value != this.date)
{
this.date = value;
setActualDate(this.date);
update();
if (this.PropertyChanged != null)
{
this.PropertyChanged(this,
new PropertyChangedEventArgs("NewDate"));
}
}
}
}
public void update()
{
zodiac = MoonCalculus.getZodiac();
...
ZodiacString = zodiac;
}
public String ZodiacString
{
get { return zodiacString; }
set
{
if (zodiacString != value)
{
zodiacString = AppResources.ResourceManager.GetString(value);
}
}
}
Upvotes: 1
Views: 883
Reputation: 4268
Try getting rid of update()
, and get rid of the setter for ZodiacString
.
Two reasons - it's not needed, and
In the getter, do the work of update. This is better then your current implementation too -- the value being used as a parameter for AppResources.ResourceManager.GetString(value);
is 'code smell' because it's not making obvious it's true intentions. (using as a parameter rather than setting ZodiacString to it's value)
public DateTime Date
{
get { return date; }
set
{
if (value != this.date)
{
this.date = value;
setActualDate(this.date);
RaisePropertyChanged("Date");
RaisePropertyChanged("NewDate");
RaisePropertyChanged("ZodiacString");
}
}
}
private void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}
public String ZodiacString
{
get {
zodiac = MoonCalculus.getZodiac();
...
return zodiac; }
}
Upvotes: 1
Reputation: 22492
PropertyChanged
when ZodiacString
is setMode=OneWay
, which is the default anyway. You want Mode=TwoWay
.Upvotes: 2