アプリケーションテンプレートの生成
flutter create watashi_app
アプリケーションの実行
アプリケーションのトップフォルダ(pubspec.yaml のあるフォルダ)で、次を実行
flutter run
flutter create watashi_app
flutter run
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApp3 { /// <summary> /// MainWindow.xaml の相互作用ロジック /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void InputChangedHandler(object sender, RoutedEventArgs e) { Debug.WriteLine("InputChangedHanlder is called."); } } public static class EventHelper { public static readonly DependencyProperty IsEventRaisingProperty = DependencyProperty.RegisterAttached("IsEventRaising", typeof(bool), typeof(EventHelper), new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnIsEventRaisingChanged))); public static bool GetIsEventRaising(DependencyObject sender) { return (bool)sender.GetValue(IsEventRaisingProperty); } public static void SetIsEventRaising(DependencyObject sender, bool ier) { sender.SetValue(IsEventRaisingProperty, ier); } public static readonly RoutedEvent InputChangedEvent = EventManager.RegisterRoutedEvent( "InputChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(EventHelper) ); public static void AddInputChangedHandler(DependencyObject sender, RoutedEventHandler handler) { UIElement element = sender as UIElement; if (element != null) { element.AddHandler(InputChangedEvent, handler); } } public static void RemoveInputChangedHandler(DependencyObject sender, RoutedEventHandler handler) { UIElement element = sender as UIElement; if (element != null) { element.RemoveHandler(InputChangedEvent, handler); } } private static void OnIsEventRaisingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { (sender as TextBox).TextChanged += (_s, _e) => { (sender as TextBox).RaiseEvent(new RoutedEventArgs(InputChangedEvent)); }; } } }
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp3" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:Custom="http://infragistics.com/DockManager" x:Class="WpfApp3.MainWindow" mc:Ignorable="d" Title="MainWindow X" Height="350" Width="525"> <Grid> <TextBox local:EventHelper.IsEventRaising="True" local:EventHelper.InputChanged="InputChangedHandler" /> </Grid> </Window>
<Slider x:Name="slider1" HorizontalAlignment="Left" Margin="49,36,0,0" VerticalAlignment="Top" Width="257" /> <TextBox HorizontalAlignment="Left" Height="24" Margin="49,85,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="257" Text="{Binding ElementName=slider1, Path=Value}"/>
<Window x:Class="TriggerDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:TriggerDemo" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> <Button Content="button1" Height="30" Width="200"> <Button.Resources> <Style TargetType="Button"> <Style.Triggers> <!--Content が "button1" ならば--> <Trigger Property="Content" Value="button1"> <!--背景色を赤色に変更--> <Setter Property="Background" Value="Red"/> </Trigger> <!--Button 上にマウスがホバーしていたら--> <Trigger Property="IsMouseOver" Value="True"> <!--前景色を白色に変更--> <Setter Property="Foreground" Value="White"/> </Trigger> </Style.Triggers> </Style> </Button.Resources> </Button> </Grid> </Window>
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } public static double GetRecord(DependencyObject obj) { return (double)obj.GetValue(RecordProperty); } public static void SetRecord(DependencyObject obj, double value) { obj.SetValue(RecordProperty, value); } // Using a DependencyProperty as the backing store for Record. This enables animation, styling, binding, etc... public static readonly DependencyProperty RecordProperty = DependencyProperty.RegisterAttached("Record", typeof(double), typeof(MainWindow), new FrameworkPropertyMetadata(0.0) ); private void Button_Click(object sender, RoutedEventArgs e) { var btn = sender as Button; Debug.WriteLine(btn.GetValue(RecordProperty)); } }
<Window x:Class="AttachedPropertyDemo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:AttachedPropertyDemo" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> <Button Content="abc" Height="30" Width="200" local:MainWindow.Record="3.0" Click="Button_Click"/> </Grid> </Window>
<Window x:Class="WpfApp3.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp3" mc:Ignorable="d" xmlns:sys="clr-namespace:System;assembly=mscorlib" Title="MainWindow X" Height="350" Width="525"> <Grid> <Grid.Resources> <sys:Int32 x:Key="num1">123</sys:Int32> </Grid.Resources> <TextBox x:Name="textBox1" Height="30" Width="250" Text="abc" ToolTip="{Binding Source={StaticResource num1}}"/> </Grid> </Window>
<Window x:Class="WpfApp3.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp3" mc:Ignorable="d" Title="MainWindow X" Height="350" Width="525"> <Grid> <TextBox x:Name="textBox1" Height="30" Width="250" Text="abc" ToolTip="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=Title}"/> </Grid> </Window>