110,530
社区成员
发帖
与我相关
我的任务
分享
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
"Icon",
typeof(String),
typeof(MyImage),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsRender,
(sender, e) =>
{
(sender as MyImage).Icon = e.NewValue.ToString();
}
)
);
应为FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
//
// 摘要:
// 此依赖项属性的数据绑定的 System.Windows.Data.BindingMode 默认为 System.Windows.Data.BindingMode.TwoWay。
BindsTwoWayByDefault = 256,
<UserControl x:Class="EditorV2.Control.MyImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Edit="clr-namespace:EditorV2">
<Button Click="Button_Click" Width="80" Height="80">
<Image Margin="3" Stretch="Fill" x:Name="Image"/>
</Button>
</UserControl>
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
"Icon",
typeof(String),
typeof(MyImage),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsRender,
(sender, e) =>
{
(sender as MyImage).Icon = e.NewValue.ToString();
}
)
);
public String Icon
{
get
{
string s = (String)GetValue(IconProperty);
return s;
}
set
{
SetValue(IconProperty, value);
Image.Source = new ImageConverter().Convert(value, Type.GetType("System.Windows.Media.ImageSource"), null, new System.Globalization.CultureInfo("en-US")) as ImageSource;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
m_OpenFileDialog.Title = Title;
String IconFloderPath = AppDomain.CurrentDomain.BaseDirectory + Floder;
if (!System.IO.Directory.Exists(IconFloderPath)) System.IO.Directory.CreateDirectory(IconFloderPath);
m_OpenFileDialog.InitialDirectory = IconFloderPath;
m_OpenFileDialog.Filter = String.IsNullOrEmpty(Filter) ? "图片文件|*.jpeg" : Filter;
m_OpenFileDialog.ValidateNames = true;
m_OpenFileDialog.CheckPathExists = true;
m_OpenFileDialog.CheckFileExists = true;
if (m_OpenFileDialog.ShowDialog() == true)
{
Icon = Floder + "\\" + m_OpenFileDialog.SafeFileName;
}
}