我不确定为什么没有在Binding上调用该属性.这是代码:
<myusercontrol
Text ="{Binding Description, UpdateSourceTrigger=LostFocus,Mode=TwoWay, ValidatesOnDataErrors=True}"
IsReadOnly ="{Binding AllowEditing}"
/>
Run Code Online (Sandbox Code Playgroud)
这是myusercontrol IsReadOnly属性:
public static DependencyProperty IsReadOnlyProperty = DependencyProperty.Register("IsReadOnly", typeof (bool),
typeof (
myusercontrol));
public bool IsReadOnly
{
get
{
return ((bool) GetValue(IsReadOnlyProperty));
}
set
{
MessageBox.Show(value.ToString());
SetValue(IsReadOnlyProperty, !value);
OnPropertyChanged("IsReadOnly");
}
}
Run Code Online (Sandbox Code Playgroud)
永远不会显示消息框!有任何想法吗!
我创建了一个自定义按钮,因为我想要一个图像和文本在其中,如下所示:
<Style TargetType="{x:Type Local:ImageButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Local:ImageButton}">
<StackPanel Height="Auto" Orientation="Horizontal">
<Image Margin="0,0,3,0" Source="{TemplateBinding ImageSource}"/>
<TextBlock Text="{TemplateBinding Content}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
这里,ImageButton是一个继承自Button类并将ImageSource作为依赖项属性的类.
但我想保持原始按钮的外观和感觉.我该怎么做?谢谢.
如何在缺少绑定路径文件时显示默认图像?
<Image Source="{Binding DisplayedBook.ImagePath}" />
Run Code Online (Sandbox Code Playgroud)
我的解决方案:使用转换器,检查图像是否存在并返回适当的路径.
我是wpf的新手.我必须ToolBar像ms-office 2003工具栏一样在wpf中创建一个浮动.所以我可以把它放在顶部 - 底部,左 - 右,就像2003年办公室一样.
请帮我 .......................
我正在通过MVVM学习WPF,对于初学者,我观看了Jason Dolinger在MVVM上的视频。在他提到的内容中,将MVVM与WPF一起使用的优势之一是双向数据绑定。我的问题是双向数据绑定是什么意思?1)将控件(视图)中的数据绑定到VM中的属性,以及2)集合或属性中的任何更改都反映在视图中的功能是否具有这种功能?如果我错了,谁能请我详细解释一下它的含义和优点?这可能是一个非常简单的疑问,但是我对WPF还是陌生的,它是术语,现在已经远离WinForms。
我有以下用户控件:一个点及其名称:
<UserControl x:Class="ShapeTester.StopPoint"
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="25" d:DesignWidth="100">
<StackPanel>
<Ellipse Stroke="DarkBlue" Fill="LightBlue" Height="10" Width="10"/>
<TextBlock Text="Eiffel Tower"/>
</StackPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
这很酷。
现在,我有一个面板,在女巫中,我需要恢复我用鼠标击中的停止点:
public partial class StopsPanel : UserControl
{
private List<StopPoint> hitList = new List<StopPoint>();
private EllipseGeometry hitArea = new EllipseGeometry();
public StopsPanel()
{
InitializeComponent();
Initialize();
}
private void Initialize()
{
foreach (StopPoint point in StopsCanvas.Children)
{
point.Background = Brushes.LightBlue;
}
}
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// Initialization:
Initialize();
// Get mouse click point:
Point pt …Run Code Online (Sandbox Code Playgroud) 我试图创建一个自定义控件,具有半透明的圆形背景:
<Canvas>
<TextBlock x:Name="StopText" Text="Some test text"/>
<Rectangle Fill="SkyBlue"
Width="{Binding Source=StopText, Path=ActualHeight}"
Height="20"
RadiusX="5" RadiusY="5" Opacity="0.2"/>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
问题是我不能绑定到ActualHeight/ ActualWidthproperties,因为它们不是依赖项.
如何处理相同大小的矩形和文本框?
我很擅长使用线程.我试图设定一个DependencyProperty值:
public States State
{
get { return (States)GetValue(StateProperty); }
set
{
Dispatcher.BeginInvoke(DispatcherPriority.Background,
//(SendOrPostCallback)delegate { SetValue(StateProperty, value); }, //works
(Action)(()=> SetValue(StateProperty, value)), //doesnt
value);
}
}
public static readonly DependencyProperty StateProperty =
DependencyProperty.Register("State", typeof(States), typeof(FTPDownload), new UIPropertyMetadata(States.Idle));
Run Code Online (Sandbox Code Playgroud)
我意识到在setter中你必须使用SendOrPostCallback(因为它在调用方法时提供了一个参数).它不适用于Action(因为缺少参数.而且,wpf真的是一个关于它的婊子,调试并找到TargetParameterCountException的原因,"没有源可用",根本没有线索.
为什么我必须在那里使用SendOrPostCallback?我怎么知道在这种情况下这是正确的?因为实际上通过以下方式调用setter:
Dispatcher.BeginInvoke((Action)(()=>State=States.Updating), null);
Run Code Online (Sandbox Code Playgroud)
并使用SendOrPostCallback而不是当然导致TargetParameterCountException ..
只是想知道看似不一致的事情是否只是常识?感觉有点迷失在这里,至少自从谷歌搜索SendOrPostCallback,Action和BeginInvoke作为关键字没有有意义的结果.
我完成了所有工作,但是当我点击设置时,设置窗口(在nswindowcontroller中)会在我的mac上运行的其他应用程序的后面打开.我希望它在前面,以便用户在点击它时可以看到它.
谢谢你们!
说我有一个Grid,其Width被设置为Auto.在这个网格中,我想放一个正方形的新网格.为此,我希望新网格的宽度和高度相等.我以为我可以设置Width和Height父网格Width.问题是,父网格的宽度是double.NaN,因为它设置为auto.
我的问题是,有没有办法获得ActualWidth这个父网格,以便我知道它有多宽?如果没有,是否有另一种方法来创建适合父网格的矩形网格?
wpf ×7
data-binding ×3
actualwidth ×2
c# ×2
.net ×1
actualheight ×1
begininvoke ×1
binding ×1
cocoa ×1
hittest ×1
image ×1
macos ×1
silverlight ×1
statusbar ×1
styles ×1
toolbar ×1
two-way ×1
uielement ×1
window ×1