IValueConverterはEto.Forms 2.4.0以降で存在した。が、他でつまづく。
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch(9.0) 2018-06-27
- Mono 5.16.0
- MonoDevelop 7.6 build 711
- Eto.Forms 2.4.1 拡張機能, NuGetパッケージ
前回
- http://ytyaru.hatenablog.com/entry/2020/01/31/000000
- http://ytyaru.hatenablog.com/entry/2020/01/30/000000
- http://ytyaru.hatenablog.com/entry/2020/01/29/000000
- http://ytyaru.hatenablog.com/entry/2020/01/28/000000
- http://ytyaru.hatenablog.com/entry/2020/01/27/000000
- http://ytyaru.hatenablog.com/entry/2020/01/26/000000
- http://ytyaru.hatenablog.com/entry/2020/01/25/000000
- http://ytyaru.hatenablog.com/entry/2020/01/24/000000
参考
- http://api.etoforms.picoe.ca/html/T_Eto_Forms_IValueConverter.htm
- https://github.com/picoe/Eto/wiki/Data-Binding
- http://blogs.itmedia.co.jp/mohno/2013/12/xaml15-c9fe.html
- http://mokake.hatenablog.com/entry/2017/01/06/000336
- https://qiita.com/YSRKEN/items/8ca6f4a30a41d452fddc
- https://qiita.com/Temarin/items/d9008704154eea6ce572
- https://qiita.com/tanitanin/items/c0230f2a749d7856f942
- https://msdn.microsoft.com/ja-JP/library/windows/apps/windows.ui.xaml.data.binding.converter.aspx
- https://qiita.com/snaka/items/0b59a56cbb803147a5d4
- https://en.wikipedia.org/wiki/Mono_%28software%29
- https://qiita.com/ledsun/items/6f4ef754e5ae2507e531
手順
- プロジェクト作成
- ソースコード追加
- 実行
1. プロジェクト作成
- メニュー→
ファイル
→新しいソリューション
マルチプラットフォーム
→アプリ
→Eto Application
- 名前などを適当に入力し、
Xaml
を選択する
場所
を入力する
- プロジェクトが作成される
2. ソースコード追加
MainForm.xeto
xmlns:local
, <Window.Resources>
が問題の箇所。そもそもWPFの記法なのだが、これはEto.Formsでも使えるのか?
MainForm.xeto
<?xml version="1.0" encoding="UTF-8"?> <Form xmlns="http://schema.picoe.ca/eto.forms" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MainForm" Title="My Eto Form" ClientSize="800, 600" Padding="10"> <Window.Resources> <local:StringUriConverter x:Key="StringUriConverter" /> </Window.Resources> <StackLayout> <TextBox x:Name="textBox1" Width="800" /> <WebView x:Name="webView1" Width="800" Height="600" Url="{Binding ElementName=textBox1, Path=Text, Converter={StaticResource StringUriConverter}}" /> </StackLayout>> </Form>
MainForm.xeto.cs
using System; using System.Collections.Generic; using Eto.Forms; using Eto.Drawing; using Eto.Serialization.Xaml; namespace HelloEtoXamlBindingTextBoxWebView { public class MainForm : Form { public MainForm() { XamlReader.Load(this); DataContext = new UrlViewModel(); } } }
StringUriConverter.cs
IValueConverter。よく調べたらEto.Formsにも存在した。
using System; using Eto.Forms; namespace HelloEtoXamlBindingTextBoxWebView { public class StringUriConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { //return ((string?)value == true) ? new Uri(value as string) : value; //var v = value as string; return new Uri(value as string); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { //throw new NotImplementedException(); return (value as string).ToString(); } } }
UrlViewModel.cs
モデル。
using System; using System.ComponentModel; // INotifyPropertyChanged using System.Runtime.CompilerServices; // CallerMemberName namespace HelloEtoXamlBindingTextBoxWebView { public class UrlViewModel : INotifyPropertyChanged { String url; public String Url { get { return url; } set { this.url = value; OnPropertyChanged(); } } void OnPropertyChanged([CallerMemberName] string memberName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(memberName)); } public event PropertyChangedEventHandler PropertyChanged; } }
3. 実行
- Ctrl+F5で実行
- 怒られた
- ファイルパスを辿ってexeファイルを直接叩くと強制終了する……
所感
WPFの情報ならあるが、Eto.Formsにコードをコピーしても動かない……。