标签: datatemplate

抑制 GridViewColumn 上的鼠标悬停效果

我有一个GridViewColumn与 a HeaderTemplate,其中有一个Image和 a TextBlock。当用户将鼠标悬停Image在我正在更改其不透明度时,但我仍然获得默认的标题鼠标悬停效果。当用户将鼠标悬停在图像上时如何抑制这种效果?

c# wpf xaml datatemplate

3
推荐指数
1
解决办法
5597
查看次数

将DataTemplate绑定到CustomControl问题

我得到的是一个自定义控件,它在 xaml 中实现数据模板:

<DataTemplate x:Key="Templat">
    <StackPanel>
        <TextBlock Text="Sample Text" />
        <TextBlock Text="{Binding Surname}" />
    </StackPanel>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

和自定义控制:

 <local:MyControl x:Name="MyControl1" 
      ItemTemplate="{StaticResource Templat}" Margin="0,0,-24,8"/>
Run Code Online (Sandbox Code Playgroud)

generic.xaml(在我的自定义控件库中)具有:

<ControlTemplate TargetType="local:MyControl">
   <Canvas Name="LayoutRoot" Height="{TemplateBinding Height}" 
           Width="{TemplateBinding Width}" 
           Background="{TemplateBinding Background}" 
           CacheMode="BitmapCache">

      <Canvas Name="ItemsHost" Margin="10,185,0,0" Height="615" 
              Width="{TemplateBinding Width}" CacheMode="BitmapCache">
           <local:CustomItem x:Name="Item1" 
                  ContentTemplate="{TemplateBinding ItemTemplate}" />
           <local:CustomItem x:Name="Item2" 
                  ContentTemplate="{TemplateBinding ItemTemplate}" />
      </Canvas>  
   </Canvas> 
</ControlTemplate> 
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

我创建了一个自定义项目控件,其中有一些自定义内容控件。我希望它们都具有相同的内容模板,因此我将它们的内容模板绑定到父控件中定义的 itemtemplate。

我的问题是控件将显示带有“示例文本”文本的文本块,但不显示带有绑定值的文本块。我试图在代码隐藏中指定 DataContext(例如DataContext = new Person() { Surname="Johnson" }或通过 xaml)。它们都不起作用。

DataContext(Person 类)看起来传递正确,但传递的 DataTemplate 缺少表达式'{Binding Surname}'。您有任何想法可能会出现什么问题吗?

data-binding silverlight wpf custom-controls datatemplate

3
推荐指数
1
解决办法
6579
查看次数

如何在WPF中的模板化TabItem上获得关闭按钮?

我有一个TabControlTabItems的DataTemplat主编.该模板似乎正常工作,因为我要在其中显示的用户控件TabItem正确显示.

我不确定的是如何让"x"显示出来,TabItem因此我可以关闭每个标签,因为它们是通过模板动态生成的.

作为WPF的新手,我开始接受许多概念,但是TabControl给了我很多麻烦,所以我很可能让模板可行,但不可维护.

这就是我所拥有的,我希望能够关闭每一个TabControl.我还需要能够在TabControl关闭时触发自定义事件.

<UserControl x:Class="Russound.Windows.UI.UserControls.CallLog.CaseReaderWpf"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:CallLog="clr-namespace:Russound.Windows.UI.UserControls.CallLog"
    Height="637" Width="505">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Russound.Windows;component/UI/RussoundDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <TabControl x:Name="tabCases" >
        <TabControl.ItemTemplate>
            <DataTemplate DataType="{x:Type TabItem}">
                <StackPanel>
                    <TextBlock Text="{Binding Path=Id}" />
                </StackPanel>
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate DataType="{x:Type TabItem}">
                <CallLog:CaseReadOnlyDisplay DataContext="{Binding}" />
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

wpf styles datatemplate .net-3.5

2
推荐指数
1
解决办法
1万
查看次数

将样式添加到HierarchicalDataTemplate生成的MenuItems

我正在使用HierarchicalDataTemplate将我的分层数据添加到Menu-Control.

<HierarchicalDataTemplate DataType="{x:Type local:MyType}" ItemsSource="{Binding Path=SubItems}">
    <StackPanel>
        <TextBlock Text="{Binding Name}"/>
    </StackPanel>
</HierarchicalDataTemplate>
Run Code Online (Sandbox Code Playgroud)

我的菜单是这样创建的

<Menu>
    <MenuItem ItemsSource="{Binding MyCollection}" Header="MainItem"></MenuItem>
</Menu>
Run Code Online (Sandbox Code Playgroud)

例如,如何为这些生成的MenuItem添加样式以设置IsCheckable属性.重要的是主MenuItem(此处名为"MainItem"的标题)不应用此样式,因此它不可检查.

我尝试了几种方法<Style>,<DataTemplate但没有成功.

wpf xaml datatemplate hierarchicaldatatemplate

2
推荐指数
1
解决办法
1726
查看次数

如何在Silverlight XAML中引用另一个命名空间中的绑定转换器?

由于您显然无法在C#中创建Silverlight DataTemplate,因此我尝试在XAML中创建一个.我有一个我需要引用的转换器,我在另一个命名空间中用C#定义.我试过这样做:

<UserControl.Resources>
        <DataTemplate x:Key="PriceTemplate">
            <TextBlock Text="{Binding Price, Converter={Converters:PriceConverter}}" />
        </DataTemplate>
    </UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)

转换器是指向正确名称空间的xmlns.但是,我得到一个编译错误,说:

类型'转换器:PriceConverter'用作标记扩展名,但不是从MarkupExtension派生的.

我尝试将System.Windows.Markup.MarkupExtension添加为我的转换器的父级,但它显然在Silverlight中不存在.

如何在XAML中引用我的转换器,而不必在XAML中重写它?

c# silverlight markup xaml datatemplate

2
推荐指数
1
解决办法
5184
查看次数

WrapPanel中的VerticalAlignment - 如何使其正常工作?

我有一个奇怪的问题.

情况就是这样.我有一个ListView定制的自定义GroupStyle,使数据显示在Expanders中,其中有一个WrapPanel包含StackPanels(包含一个ToggleButton +一个自定义控件)StackPanel默认情况下,自定义控件不可见,并在ToggleButton选中时显示.但是,当我检查a时ToggleButton,会出现自定义控件,位于同一行的所有其他控件将移动到垂直中心.理想情况下,我希望其他成员能够保持领先地位.我试着尽VerticalAlignment="Top"我所能,不管怎样都不会改变.

成像问题:

扩展器的初始状态:

之前扩张

一旦ToggleButton被点击时,会出现以下情况:

扩张后

如您所见,"测试分析​​"按钮移动到中心位置.我希望它与原版保持在同一个地方.

而且,我已经在单独的DataTemplates对象中定义了所有这些样式.这里有一些轻量代码(我刚刚删除了这里的问题无用,不会让你阅读大量的XAML代码:)):

扩展器的内容属性:

<Expander.Content>
    <WrapPanel Background="White" VerticalAlignment="Top">
        <ItemsPresenter VerticalAlignment="Top"/>
    </WrapPanel>
</Expander.Content>
Run Code Online (Sandbox Code Playgroud)

清单的ItemsPanel:

<ItemsPanelTemplate >
    <WrapPanel 
         Width="{Binding (FrameworkElement.ActualWidth),
         RelativeSource={RelativeSource 
                         AncestorType=Expander}}"
         ItemWidth="{Binding (ListView.View).ItemWidth,
         RelativeSource={RelativeSource AncestorType=ListView}}"

         ItemHeight="{Binding (ListView.View).ItemHeight,
         RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
Run Code Online (Sandbox Code Playgroud)

清单的ItemsTemplate:

<StackPanel Orientation="Vertical" Height="Auto" Width="Auto" VerticalAlignment="Top" >
    <ToggleButton BorderBrush="{x:Null}" Background="{x:Null}" IsChecked="{Binding Value.IsToLaunch, Mode=TwoWay}"
              Command="{Binding DataContext.UpdateGroupCheckingsCommand,
                                RelativeSource={RelativeSource FindAncestor,
                                AncestorType={x:Type UserControl}}}"> …
Run Code Online (Sandbox Code Playgroud)

wpf wrappanel datatemplate wpf-controls vertical-alignment

2
推荐指数
1
解决办法
3787
查看次数

访问WPF ListBox中的ListBoxItem控件

在WPF应用程序中,我使用在XAML中的以下DataTemplate中定义的ItemTemplate创建Listbox:

<DataTemplate x:Key="ListItemTemplate">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel>
      <Button/>
      <Button/>
      <Button Name="btnRefresh" IsEnabled="false"/>
      <TextBlock/>
      <TextBlock/>
      <TextBlock/>
      <TextBlock/>
    </StackPanel>
    <TextBox/>
  </Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

生成ListBox后,我需要在所有ListBoxItem上更改以下按钮IsEnabled propety为true: <Button Name="btnRefresh" IsEnabled="false"/>

问题:

我无法访问ListBoxItem,因此无法使用该按钮访问其子项.

在WPF中是否有像ListBox.Descendents()这样的Silverlight或任何其他方式来获取该按钮,

wpf listbox datatemplate listboxitem

2
推荐指数
1
解决办法
8507
查看次数

在DataTemplate DataType中使用命名空间

我正在尝试使用ListBox和ItemsSource属性显示来自YouTube的视频列表.

我现在的工作(下图),但现在我需要格式化我的数据.

<ListBox Name="lbVideos" ItemsSource="{Binding Source={StaticResource listOfVideos}}"/>
Run Code Online (Sandbox Code Playgroud)

为此,我使用的是DataTemplate,但问题是该类型是Google.YouTube.Video.

<Application x:Class="YouTube_Notifier.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Startup="AppStartup"
    xmlns:src="clr-namespace:YouTube_Notifier" 
    xmlns:System="clr-namespace:System;assembly=mscorlib">
    <Application.Resources>
        <DataTemplate DataType="{x:Type src:Google:YouTube:Video}">
        </DataTemplate>
    </Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)

上面的代码导致我收到错误"Type'src:找不到Google.YouTube.Video".

我要问的是如何在DataTemplate中使用命名空间?

data-binding wpf xaml namespaces datatemplate

2
推荐指数
1
解决办法
3547
查看次数

在DataTemplate中使用自定义控件时,绑定不起作用

我正在尝试用自定义控件替换ListView DataTemplate中的标准控件,但绑定似乎无法正常工作.这是ListView的定义:

<Grid>
    <ListView ItemsSource="{Binding DataItemsCollection}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="Static text" />
                    <TextBlock Text="{Binding DataItemText}" />
                    <BindingTest:CustomControl CustomText="{Binding DataItemText}" />
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</Grid>
Run Code Online (Sandbox Code Playgroud)

DataItemsCollection是一个可观察的类型集合

public class DataItemClass : INotifyPropertyChanged
{
    string _dataItemText;
    public string DataItemText
    {
        get { return _dataItemText; }
        set { _dataItemText = value; Notify("DataItemText");  }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void Notify(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}
Run Code Online (Sandbox Code Playgroud)

主窗口代码如下所示:

public partial class MainWindow : Window
{
    public ObservableCollection<DataItemClass> …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf custom-controls datatemplate

2
推荐指数
1
解决办法
3551
查看次数

wpf listbox和datatemplate里面有网格

我有一个问题.我希望能有ListBoxDataTemplate作为Grid.该网格有2列.我想将第一列宽度设置为3*另一列*.这该怎么做?我会复制我的代码.

<ListBox x:Name="commandListbox" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Stretch">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Column="0" Text="{Binding}"/>
                <TextBlock Grid.Column="1" Text="icon" />
           </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>                
</ListBox>
Run Code Online (Sandbox Code Playgroud)

wpf grid listbox datatemplate

2
推荐指数
2
解决办法
2万
查看次数