鉴于以下内容:
我有以下两个问题:
我想在我的应用程序中实现"请勿打扰"模式.基本上他们启用了此模式,我们阻止某些应用程序(如MSN/Skype /等)破坏了用户的注意力.
这是一款在线游戏,有些用户要求这样做,我们想尝试一下.
我不知道从哪里开始.Windows是否具有 Skype等应用敏感的全局"忙碌"模式?我听说过Windows演示模式,但我认为它只会让我们走到一半.
否则,是否有一种良好的熊方式以编程方式将Skype/IM应用程序设置为"忙碌"?
因此,为了使问题简单,我需要使用类似的东西数十次;
<Rectangle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<ei:ChangePropertyAction TargetName="AnotherObjectOnTheView"
PropertyName="Visibility"
Value="Visible" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Rectangle>
Run Code Online (Sandbox Code Playgroud)
但显然我不想在我需要的地方粘贴几十次。所以我尝试将它们放入ContentControl类似这样的东西中:
<Style x:Key="MyThingy" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Rectangle>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<ei:ChangePropertyAction TargetName="AnotherObjectOnTheView"
PropertyName="Visibility"
Value="Visible" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Rectangle>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
有了这个想法,我可以通过调用模板来替换每个实例的所有内容;
<ContentControl Style="{StaticResource MyThingy}"/>
Run Code Online (Sandbox Code Playgroud)
除了问题是,当嵌入ContentControl,交互触发器似乎不会触发。它会很好地显示模板化项目,但似乎忽略了触发器?
所以问题是,为什么附加到模板化项目的触发器被忽略,或者是否有更好的方法来完成我想要的事情?
我需要在设置时订阅控件的事件ContentControl.Content。
请问,我可以在我的代码中放入什么事件来设置它?
我尝试使用SourceUpdatedand DataContextChanged,但它不起作用。
我创造了一个美丽的WindowChrome风格,适用于我的窗户.ContentControl但是,当我添加到我的样式时,应用程序进入中断模式.
我已经拼凑了这个youtube视频,本文,这个SO问题和微软的文档中的代码,我已经提出了以下代码.
注意:下面的代码都被认为是相关的,因为应用程序无法使用这些部分中的任何一个运行(是的,我知道它可以在没有代码隐藏的情况下运行,但是令人烦恼的是必须从Visual Studio而不是关闭按钮停止应用程序 -也是我想要完成的事情).我实际上已经缩减了下面的代码,以便更容易使用.
<Style x:Key="TestWindow" TargetType="{x:Type Window}">
<Setter Property="Background" Value="#FF222222"/>
<Setter Property="BorderBrush" Value="WhiteSmoke"/>
<Setter Property="BorderThickness" Value="5,30,5,5"/>
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="20"
CornerRadius="0"
GlassFrameThickness="0,0,0,-1"
NonClientFrameEdges="None"
ResizeBorderThickness="5"
UseAeroCaptionButtons="True"/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<AdornerDecorator>
<ContentPresenter/>
</AdornerDecorator>
</Border>
<DockPanel LastChildFill="True" VerticalAlignment="Top" Height="30">
<StackPanel DockPanel.Dock="Right"
Orientation="Horizontal"
VerticalAlignment="Center">
<Button x:Name="Button_Close"
WindowChrome.IsHitTestVisibleInChrome="True"
Width="{Binding ActualHeight, RelativeSource={RelativeSource …Run Code Online (Sandbox Code Playgroud) 我偶然发现了著名的TabControl虚拟问题。我想TabControl用样式列表(以显示选项卡)和ContentControl(以显示选项卡的内容)替换 。但是,如果两个内容共享其类型,则似乎ContentControl具有相同的重用行为。DataTemplates
有没有办法强制为所有显示的项目ContentControl单独实例化DataTemplates?
编辑:示例
假设我们有以下 UserControl 充当文档视图模型的 DataTemplate:
文档控件.xaml:
<UserControl x:Class="ControlTemplateProblem.DocumentControl"
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"
xmlns:local="clr-namespace:ControlTemplateProblem"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Loaded="UserControl_Loaded"
Unloaded="UserControl_Unloaded"
x:Name="Main">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Index}" />
<TextBlock Text="{Binding ElementName=Main, Path=StoredIndex}" />
</StackPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
文档控件.xaml.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
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; …Run Code Online (Sandbox Code Playgroud) 我想将一个DataGrid放在HeaderedContentControl中,但DataGrid没有得到一个垂直的Scrollbar.它看起来大小可以同时容纳所有行,底部从视图中消失.
如果我将相同的DataGrid放在Border elelemnt中,我会得到我想要的行为.
我把它简化为这个最小的例子:
<Grid>
<HeaderedContentControl Margin="10,10,10,161" >
<HeaderedContentControl.Header >test</HeaderedContentControl.Header>
<!-- I want it Here but then no Vertical Scroll-->
<DataGrid ItemsSource="{Binding Path=AllData}"
AutoGenerateColumns="True" />
</HeaderedContentControl>
<Border Margin="10,169,10,10">
<!--Here it does scroll -->
<DataGrid ItemsSource="{Binding Path=AllData}"
AutoGenerateColumns="True" />
</Border>
</Grid>
Run Code Online (Sandbox Code Playgroud)
几点说明:
假设我有以下控制模板:
<ControlTemplate x:Key="Test">
<Grid>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Width="33" Height="33" CornerRadius="3"/>
<ContentControl Content="{TemplateBinding Property=ContentControl.Content}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
如何更改wpf中的控件内容?我尝试过类似的东西
<Control Template="{StaticResource Test}" BorderBrush="Black" Content="aa"></Control>
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,它说我无法识别或找不到属性内容。
我有一个 UserControl,其中包含两个需要在运行时绑定到它们的不同 UserControl 视图的 ContentControl。此处提到的附加属性解决方案在 Silverlight 中似乎不起作用。或者,我做错了什么。我也发现了这个,但它也没有带来任何快乐。
我通过将其命名为“ActiveItem”来使单个 ContentControl 工作。但是,当然,我不能有两个同名的 ContentControl。
在此先感谢您的帮助,
吉姆
silverlight mvvm contentcontrol silverlight-4.0 caliburn.micro
我必须在我的主页上插入 SVG 徽标作为类别名称,每个类别都有其徽标。它们在App.xaml中定义的DataTemplates,我包括他们在我的主页ContentControl有DataTemplateSelector显示正确的标志(列入标识工作的无模板选择,但我需要它dinamically包括在内)。
这是主页上的xaml:
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6" Name="CategoryName">
<Button AutomationProperties.Name="Group Title" Click="Category_Click" Style="{StaticResource TextPrimaryButtonStyle}">
<ContentControl Name="CategoryLogo" Content="{Binding Category.Name}" ContentTemplateSelector="{StaticResource LogoTemplateSelector}" IsHitTestVisible="True" Margin="3,-7,10,10"/>
</Button>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
Run Code Online (Sandbox Code Playgroud)
这是我的DataTemplateSelector:
public class LogoTemplateSelector : DataTemplateSelector
{
public string DefaultTemplateKey { get; set; }
protected override DataTemplate SelectTemplateCore(object item, Windows.UI.Xaml.DependencyObject container)
{
var category = item as String;
DataTemplate dt = null;
switch (category)
{
case "Category1": dt = FindTemplate(App.Current.Resources, "Logo1");
break;
case …Run Code Online (Sandbox Code Playgroud) contentcontrol ×10
wpf ×6
xaml ×5
c# ×3
silverlight ×3
border ×1
c++ ×1
data-binding ×1
events ×1
focus ×1
mvvm ×1
styles ×1
winapi ×1
windows ×1
wpf-4.0 ×1
wpfdatagrid ×1
xml ×1