我要在我的程序中添加一个WPF Ribbon UI.
根据您的经验,什么是最好的WPF控件套件,包括功能区控件?
谢谢!
我有以下代码:
void Test()
{
currentImage.Source = GetBitmap();
RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
rtb.Render(currentImage);
}
Run Code Online (Sandbox Code Playgroud)
这段代码应该渲染currentImage,这是我的xaml中的一个Image控件到RenderTargetBitmap.
它不起作用,rtb返回一个空白图像,问题是currentImage还没有渲染自己,所以这种行为是预期的,我认为......
为了解决这个问题,我编写了这段代码:
void Test()
{
currentImage.Source = GetBitmap();
this.Dispatcher.BeginInvoke((Action)delegate()
{
RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
rtb.Render(currentImage);
}, System.Windows.Threading.DispatcherPriority.Render, null);
}
Run Code Online (Sandbox Code Playgroud)
基本上,我等待currentImage被渲染,然后我可以将它正确渲染到我的RenderTargetBitmap.
有没有办法让它工作而不使用这种解决方法?强制Image控件在内存中渲染可能吗?
谢谢!
如何使用单选按钮"IsChecked"属性控制文本框的可见性?
我有一个两个文本框,让我们说txtbox1和txtbox2,我想基于单选按钮IsChecked属性绑定这两个文本框的visibily.下面是我正在尝试的XAML代码:
<RadioButton
x:Name="radioBtn"
IsChecked="True"
Margin="5"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="0">Enter Constant Values</RadioButton>
<TextBox Visibility="{Binding Path = IsChecked, ElementName = radioBtn}" />
Run Code Online (Sandbox Code Playgroud)
我应该使用Convertor吗?请帮忙!!
如何取消数据绑定WPF ListBox中的用户选择?source属性设置正确,但ListBox选择不同步.
我有一个MVVM应用程序,如果某些验证条件失败,需要取消WPF ListBox中的用户选择.验证由ListBox中的选择触发,而不是通过"提交"按钮触发.
该ListBox.SelectedItem属性绑定到一个ViewModel.CurrentDocument属性.如果验证失败,则视图模型属性的setter退出而不更改属性.因此,ListBox.SelectedItem绑定的属性不会更改.
如果发生这种情况,视图模型属性setter会在它退出之前引发PropertyChanged事件,我认为这足以将ListBox重置回旧选择.但这不起作用 - ListBox仍然显示新的用户选择.我需要覆盖该选择并将其与source属性同步.
如果不清楚,这里有一个例子:ListBox有两个项目,Document1和Document2; 选择了Document1.用户选择Document2,但Document1无法验证.该ViewModel.CurrentDocument属性仍设置为Document1,但ListBox显示已选择Document2.我需要将ListBox选择返回到Document1.
这是我的ListBox绑定:
<ListBox
ItemsSource="{Binding Path=SearchResults, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding Path=CurrentDocument, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
Run Code Online (Sandbox Code Playgroud)
我尝试使用从ViewModel(作为事件)到View(订阅事件)的回调,强制将SelectedItem属性返回到旧选择.我使用事件传递旧文档,它是正确的(旧选择),但ListBox选择不会更改回来.
那么,如何将ListBox选项与其SelectedItem属性绑定的视图模型属性同步返回?谢谢你的帮助.
我想为我的GridSplitter设置样式,就像添加点一样(如http://msdn.microsoft.com/en-us/library/aa970265.aspx上所示).
我还想在mouseOver上更改gridsplitter颜色,或者应用Aero Theme.
<Style x:Key="GridSplitterStyle1" TargetType="{x:Type GridSplitter}">
<Setter Property="Background"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="PreviewStyle">
<Setter.Value>
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Fill="#80000000"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridSplitter}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--Theme-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
<GridSplitter x:Name="gridSplitterTreeNodes" Width="10"
BorderThickness="1,0" Cursor="SizeWE"
RenderTransformOrigin="-1.2,0.507" ShowsPreview="True"
Style="{DynamicResource GridSplitterStyle1}">
<GridSplitter.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE3EFFF" Offset="0"/>
<GradientStop Color="#FFAFD2FF" Offset=".45"/>
</LinearGradientBrush>
</GridSplitter.Background>
</GridSplitter>
Run Code Online (Sandbox Code Playgroud) 创建一个UserControl应该能够包含WPF中可用的任何可视子项的子项,子项显示在一个容器中,该容器是一个子容器UserControl.
我无法设法让我的容器中的孩子正确显示,我尝试了serval方式,并没有找到一种适用于设计师的方法.我也尝试使用ContentControl但没有显示任何内容.
首先,我找到了这个链接,我尝试了一些变化.我设法在正确的容器中显示内容,但它在设计器中不起作用,因为content-property是set-private而设计者想要覆盖它.将所有内容放在XAML中都有效,但在与设计师合作时这并不好.这可能是最喜欢的方式.
在此之后我试图ContentControl通过将它的Content-property绑定到UIElementCollection-type 的可绑定属性来使用.这种方法不会给设计师带来任何错误,但我必须承认我从未Button在容器中看到任何控件(例如a ).它保持空白但添加了孩子.
经过一段时间寻找一个简单快捷的解决方案后,我决定在这里寻求解决方案.我有点失望.如果微软可以将样本带入MSDN,那将非常有用.
我确信必须有一种简单的方法来存档.
感谢Andrei Gavrila和jberger,我将其存档以创建一个显示内容的节点(请参阅下面的代码),但仍有两个问题: - 没有设计师支持 - 边框(请参阅xaml)未在设计器中显示,并且在应用程序时未显示正在运行甚至没有保证金
public class NodeContent : ContentControl
{
static NodeContent()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NodeContent), new FrameworkPropertyMetadata(typeof(NodeContent)));
}
}
public partial class Node : UserControl, INotifyPropertyChanged
{
UIElementCollection _Elements;
public event PropertyChangedEventHandler PropertyChanged;
public UIElementCollection NodeContent
{
get { return _Elements; }
set
{
_Elements = …Run Code Online (Sandbox Code Playgroud) 有什么区别:
HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"在WPF的文本框中?
示例示例:
<TextBox HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Height="100"
TextWrapping="Wrap"
AcceptsReturn="True"
></TextBox>
Run Code Online (Sandbox Code Playgroud) 我首先让照片做一些谈话.

所以你看,我想创建一个支持绑定到父窗口的DataContext的WPF用户控件.用户控件只是一个Button和一个带有自定义ItemTemplate的ListBox,用于显示带有Label和Remove Button的东西.
"添加"按钮应调用主视图模型上的ICommand,以便在选择新事物(IThing实例)时与用户进行交互.用户控件中ListBoxItem中的Remove按钮应该类似地调用主视图模型上的ICommand以请求删除相关内容.要使其工作,"删除"按钮必须向视图模型发送有关请求删除的事物的一些标识信息.因此,有两种类型的Command应该可绑定到此控件.像AddThingCommand()和RemoveThingCommand(IThing的东西).
我使用Click事件获得了功能,但是感觉很麻烦,在XAML背后产生了一堆代码,并且与原始MVVM实现的其余部分相冲突.我真的想要正常使用命令和MVVM.
有足够的代码来完成一个基本的演示工作,我暂缓发布整个事情来减少混乱.什么工作使我觉得我离我很近是ListBox的DataTemplate正确地绑定了Label,当父窗口将项目添加到集合时,它们会显示出来.
<Label Content="{Binding Path=DisplayName}" />
Run Code Online (Sandbox Code Playgroud)
虽然它正确显示了IThing,但当我单击它时,它旁边的Remove按钮什么都不做.
<Button Command="{Binding Path=RemoveItemCommand, RelativeSource={RelativeSource AncestorType={x:Type userControlCommands:ItemManager }}}">
Run Code Online (Sandbox Code Playgroud)
这并不是非常意外,因为没有提供特定项,但Add按钮不必指定任何内容,也无法调用该命令.
<Button Command="{Binding Path=AddItemCommand, RelativeSource={RelativeSource AncestorType={x:Type userControlCommands:ItemManager }}}">
Run Code Online (Sandbox Code Playgroud)
所以我需要的是Add按钮的"基本"修复,以便它调用父窗口的命令来添加一个东西,以及更复杂的Remove按钮修复,以便它也调用父命令但也传递它的约束.
非常感谢任何见解,
wpf ×10
wpf-controls ×10
.net ×2
c# ×2
mvvm ×2
xaml ×2
binding ×1
data-binding ×1
gridsplitter ×1
ribbon ×1
styling ×1
templating ×1