Skip to content

Instantly share code, notes, and snippets.

@kokudori kokudori/Authorizer.cs
Last active Aug 29, 2015

Embed
What would you like to do?
Twitter Client Modoki
using Livet;
namespace LivetWPFApplication1.Models
{
class Authorizer : NotificationObject
{
public bool IsAuthorized
{
get
{
// TODO 認証済みかどうかの呼び出し
return false;
}
}
}
}
using Livet;
namespace LivetWPFApplication1.ViewModels
{
public class ConfigViewModel : ViewModel
{
public void Initialize()
{
}
}
}
<Window x:Class="LivetWPFApplication1.Views.ConfigWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:l="http://schemas.livet-mvvm.net/2011/wpf"
xmlns:v="clr-namespace:LivetWPFApplication1.Views"
xmlns:vm="clr-namespace:LivetWPFApplication1.ViewModels"
Title="ConfigWindow" Height="350" Width="525">
<Window.DataContext>
<vm:ConfigViewModel/>
</Window.DataContext>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ContentRendered">
<l:LivetCallMethodAction MethodTarget="{Binding}" MethodName="Initialize"/>
</i:EventTrigger>
<i:EventTrigger EventName="Closed">
<l:DataContextDisposeAction/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
</Grid>
</Window>
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Livet;
using Livet.EventListeners;
using LivetWPFApplication1.Models;
namespace LivetWPFApplication1.ViewModels
{
public class TimeLineViewModel : ViewModel
{
Authorizer authorizer = new Authorizer();
Twitter twitter = new Twitter();
PropertyChangedEventListener propertyListener;
public void Initialize()
{
propertyListener = new PropertyChangedEventListener(twitter) {
() => twitter.TweetCount, (_, __) => RaisePropertyChanged(() => TweetCount)
};
if (!authorizer.IsAuthorized)
{
// TODO 認証の必要がある!
}
twitter.TweetCount = 100;
twitter.Tweets.Add("いぇーい");
}
public int TweetCount { get { return twitter.TweetCount; } }
public ObservableCollection<string> Tweets { get { return twitter.Tweets; } }
}
}
<Window x:Class="LivetWPFApplication1.Views.TimeLineWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:l="http://schemas.livet-mvvm.net/2011/wpf"
xmlns:v="clr-namespace:LivetWPFApplication1.Views"
xmlns:vm="clr-namespace:LivetWPFApplication1.ViewModels"
Title="TimeLineWindow" Height="350" Width="525">
<Window.DataContext>
<vm:TimeLineViewModel/>
</Window.DataContext>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ContentRendered">
<l:LivetCallMethodAction MethodTarget="{Binding}" MethodName="Initialize"/>
</i:EventTrigger>
<i:EventTrigger EventName="Closed">
<l:DataContextDisposeAction/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Label Content="{Binding TweetCount}" HorizontalAlignment="Left" Margin="200,38,0,0" VerticalAlignment="Top"/>
<ListView ItemsSource="{Binding Tweets}" HorizontalAlignment="Left" Height="100" Margin="179,92,0,0" VerticalAlignment="Top" Width="100">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
using Livet;
using System.Collections.ObjectModel;
namespace LivetWPFApplication1.Models
{
public class Twitter : NotificationObject
{
#region TweetCount変更通知プロパティ
private int _TweetCount;
public int TweetCount
{
get
{ return _TweetCount; }
set
{
if (_TweetCount == value)
return;
_TweetCount = value;
RaisePropertyChanged();
}
}
#endregion
readonly ObservableCollection<string> tweets = new ObservableCollection<string>();
public ObservableCollection<string> Tweets { get { return tweets; } }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.