summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Konstantin2013-02-02 15:47:01 +0400
committerGravatar Konstantin2013-02-13 00:13:06 +0400
commitacca89315ee8ae3a0c0b4514827eb2cb73808741 (patch)
tree68202c2052a984929c98c131952d5143d90ec1c6 /Juick
parentf8a31a6f31a1f897a3a3eb5a82b0c9ab13cad55a (diff)
add Caption to ViewModel
Diffstat (limited to 'Juick')
-rw-r--r--Juick/Classes/ExpressionHelper.cs20
-rw-r--r--Juick/Juick.csproj1
-rw-r--r--Juick/ThreadView.xaml2
-rw-r--r--Juick/ViewModels/MessageListViewModelBase.cs4
-rw-r--r--Juick/ViewModels/ThreadViewModel.cs9
5 files changed, 33 insertions, 3 deletions
diff --git a/Juick/Classes/ExpressionHelper.cs b/Juick/Classes/ExpressionHelper.cs
new file mode 100644
index 0000000..3eb453a
--- /dev/null
+++ b/Juick/Classes/ExpressionHelper.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Linq.Expressions;
+
+namespace Juick.Classes
+{
+ static class ExpressionHelper
+ {
+ public static string GetPropertyName<T>(Expression<Func<T, object>> propertyExpression)
+ {
+ var bodyExpression = propertyExpression.Body;
+ var unaryExpression = bodyExpression as UnaryExpression;
+ if (unaryExpression != null)
+ {
+ bodyExpression = unaryExpression.Operand;
+ }
+ var memberExpression = (MemberExpression)bodyExpression;
+ return memberExpression.Member.Name;
+ }
+ }
+}
diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj
index c330761..c74da5b 100644
--- a/Juick/Juick.csproj
+++ b/Juick/Juick.csproj
@@ -73,6 +73,7 @@
<Compile Include="Classes\BindingChangedEventArgs.cs" />
<Compile Include="Classes\DelegateCommand.cs" />
<Compile Include="Classes\DependencyPropertyListener.cs" />
+ <Compile Include="Classes\ExpressionHelper.cs" />
<Compile Include="Classes\ScrollViewerMonitor.cs" />
<Compile Include="Controls\HyperLinkRichTextBox.cs" />
<Compile Include="LoginView.xaml.cs">
diff --git a/Juick/ThreadView.xaml b/Juick/ThreadView.xaml
index 7de5533..ebfd166 100644
--- a/Juick/ThreadView.xaml
+++ b/Juick/ThreadView.xaml
@@ -23,7 +23,7 @@
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
- <TextBlock x:Name="ApplicationTitle" Text="JUICK" Style="{StaticResource PhoneTextNormalStyle}"/>
+ <TextBlock x:Name="ApplicationTitle" Text="{Binding Caption}" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
diff --git a/Juick/ViewModels/MessageListViewModelBase.cs b/Juick/ViewModels/MessageListViewModelBase.cs
index b9d7070..60c0a94 100644
--- a/Juick/ViewModels/MessageListViewModelBase.cs
+++ b/Juick/ViewModels/MessageListViewModelBase.cs
@@ -13,6 +13,7 @@ namespace Juick.ViewModels
{
public class MessageListViewModelBase : INotifyPropertyChanged
{
+ static readonly string IsDataLoadingPropertyName = ExpressionHelper.GetPropertyName<MessageListViewModelBase>(x => x.IsDataLoading);
bool isDataLoading;
public MessageListViewModelBase()
@@ -22,6 +23,7 @@ namespace Juick.ViewModels
}
public string RestUri { get; set; }
+ public virtual string Caption { get { return "juick"; } }
/// <summary>
/// A collection for MessageViewModel objects.
@@ -36,7 +38,7 @@ namespace Juick.ViewModels
set
{
isDataLoading = value;
- NotifyPropertyChanged("IsDataLoading");
+ NotifyPropertyChanged(IsDataLoadingPropertyName);
LoadMessagesPageCommand.NotifyCanExecuteChanged();
}
}
diff --git a/Juick/ViewModels/ThreadViewModel.cs b/Juick/ViewModels/ThreadViewModel.cs
index 4a80f31..ec1f92d 100644
--- a/Juick/ViewModels/ThreadViewModel.cs
+++ b/Juick/ViewModels/ThreadViewModel.cs
@@ -1,9 +1,11 @@
-using System;
+using Juick.Classes;
namespace Juick.ViewModels
{
public class ThreadViewModel : MessageListViewModelBase
{
+ static readonly string CaptionPropertyName = ExpressionHelper.GetPropertyName<ThreadViewModel>(x => x.Caption);
+
private int _mid;
public int Mid
{
@@ -12,7 +14,12 @@ namespace Juick.ViewModels
{
_mid = value;
RestUri = string.Format("/thread?mid={0}", _mid);
+ NotifyPropertyChanged(CaptionPropertyName);
}
}
+
+ public override string Caption {
+ get { return "#" + _mid; }
+ }
}
}