Created
February 6, 2014 03:13
-
-
Save podhmo/8837870 to your computer and use it in GitHub Desktop.
#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Application x:Class="WpfApplication7.App" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
StartupUri="MainWindow.xaml"> | |
<Application.Resources> | |
</Application.Resources> | |
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Data; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using System.Windows; | |
namespace WpfApplication7 | |
{ | |
/// <summary> | |
/// App.xaml の相互作用ロジック | |
/// </summary> | |
public partial class App : Application | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="WpfApplication7.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:c="clr-namespace:WpfApplication7" | |
Title="MainWindow" Height="350" Width="525"> | |
<Window.Resources> | |
<c:BindingData x:Key="bd" PreviewType="password"/> | |
</Window.Resources> | |
<ScrollViewer> | |
<StackPanel> | |
<StackPanel DataContext="{StaticResource bd}"> | |
<TextBlock Text="{Binding PreviewType}"></TextBlock> | |
<TextBox Text="{Binding InputString, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"></TextBox> | |
<TextBlock Text="{Binding InputString, Mode=OneWay}"></TextBlock> | |
<TextBlock Text="{Binding PreviewString, Mode=OneWay}"></TextBlock> | |
</StackPanel> | |
<StackPanel> | |
<StackPanel.DataContext> | |
<c:BindingData PreviewType="raw"/> | |
</StackPanel.DataContext> | |
<TextBlock Text="{Binding PreviewType}"></TextBlock> | |
<TextBox Text="{Binding InputString, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"></TextBox> | |
<TextBlock Text="{Binding InputString, Mode=OneWay}"></TextBlock> | |
<TextBlock Text="{Binding PreviewString, Mode=OneWay}"></TextBlock> | |
</StackPanel> | |
<c:UserControl1> | |
<c:UserControl1.DataContext> | |
<c:BindingData PreviewType="password"/> | |
</c:UserControl1.DataContext> | |
</c:UserControl1> | |
<c:UserControl1> | |
<c:UserControl1.DataContext> | |
<c:BindingData PreviewType="raw"/> | |
</c:UserControl1.DataContext> | |
</c:UserControl1> | |
<c:UserControl2> | |
<c:UserControl2.Content> | |
<c:BindingData PreviewType="password"/> | |
</c:UserControl2.Content> | |
</c:UserControl2> | |
<c:UserControl2> | |
<c:UserControl2.Content> | |
<c:BindingData PreviewType="raw"/> | |
</c:UserControl2.Content> | |
</c:UserControl2> | |
</StackPanel> | |
</ScrollViewer> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
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 WpfApplication7 | |
{ | |
public enum PreviewType { | |
raw, | |
password | |
} | |
public class BindingData : DependencyObject | |
{ | |
public static readonly DependencyProperty PreviewTypeProperty = DependencyProperty.Register( | |
"PreviewType", typeof(PreviewType), typeof(BindingData), new PropertyMetadata(PreviewType.raw)); | |
public PreviewType PreviewType { | |
get { return (PreviewType)this.GetValue(PreviewTypeProperty); } | |
set { this.SetValue(PreviewTypeProperty, value); } | |
} | |
public static readonly DependencyProperty InputStringProperty = DependencyProperty.Register( | |
"InputString", typeof(string), typeof(BindingData), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnInputStringPropertyChanged))); | |
private static void OnInputStringPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | |
{ | |
var s = e.NewValue as string; | |
switch ((PreviewType)d.GetValue(PreviewTypeProperty)) | |
{ | |
case PreviewType.password: | |
d.SetValue(PreviewStringProperty, new String((s.Select(c => '*').ToArray<char>()))); | |
break; | |
case PreviewType.raw: | |
d.SetValue(PreviewStringProperty, s); | |
break; | |
} | |
} | |
public string InputString | |
{ | |
get { return (string)this.GetValue(InputStringProperty); } | |
set { this.SetValue(InputStringProperty, value); } | |
} | |
public static readonly DependencyProperty PreviewStringProperty = DependencyProperty.Register( | |
"PreviewString", typeof(string), typeof(BindingData), new PropertyMetadata("")); | |
public string PreviewString | |
{ | |
get { return (string)this.GetValue(PreviewStringProperty); } | |
set { this.SetValue(PreviewStringProperty, value); } | |
} | |
} | |
/// <summary> | |
/// MainWindow.xaml の相互作用ロジック | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="WpfApplication7.UserControl1" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
mc:Ignorable="d" | |
d:DesignHeight="300" d:DesignWidth="300"> | |
<StackPanel> | |
<TextBlock>this is user control!!!!</TextBlock> | |
<TextBlock Text="{Binding PreviewType}"></TextBlock> | |
<TextBox Text="{Binding InputString, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"></TextBox> | |
<TextBlock Text="{Binding InputString, Mode=OneWay}"></TextBlock> | |
<TextBlock Text="{Binding PreviewString, Mode=OneWay}"></TextBlock> | |
<TextBlock Text="{Binding}" Background="AntiqueWhite"/> | |
</StackPanel> | |
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
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 WpfApplication7 | |
{ | |
/// <summary> | |
/// UserControl1.xaml の相互作用ロジック | |
/// </summary> | |
public partial class UserControl1 : UserControl | |
{ | |
public UserControl1() | |
{ | |
InitializeComponent(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="WpfApplication7.UserControl2" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
mc:Ignorable="d" | |
d:DesignHeight="300" d:DesignWidth="300"> | |
<UserControl.ContentTemplate> | |
<DataTemplate> | |
<StackPanel> | |
<TextBlock>with content template</TextBlock> | |
<TextBlock Text="{Binding PreviewType}"></TextBlock> | |
<TextBox Text="{Binding InputString, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"></TextBox> | |
<TextBlock Text="{Binding InputString, Mode=OneWay}"></TextBlock> | |
<TextBlock Text="{Binding PreviewString, Mode=OneWay}"></TextBlock> | |
<TextBlock Text="{Binding}" Background="AntiqueWhite"/> | |
</StackPanel> | |
</DataTemplate> | |
</UserControl.ContentTemplate> | |
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
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 WpfApplication7 | |
{ | |
/// <summary> | |
/// UserControl2.xaml の相互作用ロジック | |
/// </summary> | |
public partial class UserControl2 : UserControl | |
{ | |
public UserControl2() | |
{ | |
InitializeComponent(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment