标签: wpf

修改ItemsControl中项目的ZIndex

这是我的ItemsControl的代码,当鼠标移过时放大项目.
我没有设法增加当前缩放项目的ZIndex以将其放在其他项目上.

<ItemsControl ItemsSource="{Binding Path=Value}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Name}"
                       RenderTransformOrigin="0.5 0.5">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="RenderTransform">
                                    <Setter.Value>
                                        <ScaleTransform ScaleX="1.5"
                                                        ScaleY="1.5" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
Run Code Online (Sandbox Code Playgroud)

我试图在触发器中直接更改ZIndex,但它不起作用.
我似乎需要更改ContentPresenter中的ZIndex,它是VisualTree中TextBlock的Parent,而不是直接在TextBlock中.

<Setter Property="Panel.ZIndex" Value="99" />
Run Code Online (Sandbox Code Playgroud)

所以我尝试在ContentPresenter中更改ZIndex,但它仍然不起作用

<ItemsControl.ItemContainerStyle>
    <Style TargetType="{x:Type ContentPresenter}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Panel.ZIndex" Value="99" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ItemsControl.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)

有谁知道它是如何工作的?

wpf z-index itemscontrol rendertransform

6
推荐指数
1
解决办法
6804
查看次数

将System.Drawing.Font.Size转换为WPF FontSize

我需要在WPF"字体"中转换GDI字体.

myGdiFont As System.Drawing.Font
Run Code Online (Sandbox Code Playgroud)

_Family As Windows.Media.FontFamily
_Style As Windows.FontStyle
_Weight As Windows.FontWeight
_Size As Double
Run Code Online (Sandbox Code Playgroud)

特别是,我需要转换

_Size = myGdiFont.Size (???)
Run Code Online (Sandbox Code Playgroud)

WinForms字体的大小是单位或点...在WPF中是像素...如何从一个转换为另一个?

PS.
掌握克莱门斯的迹象,这是正确的吗?

  Dim myDrawingFont As New System.Drawing.Font("Arial", 10)
  Dim myWpfLabel As New Windows.Controls.Label
  myWpfLabel.FontSize = myDrawingFont.SizeInPoints * 72 / 96
Run Code Online (Sandbox Code Playgroud)

固定:

  myWpfLabel.FontSize = myDrawingFont.SizeInPoints * 96 / 72
Run Code Online (Sandbox Code Playgroud)

.net wpf fonts font-size winforms

6
推荐指数
1
解决办法
3526
查看次数

DataGridCell Validation.ErrorTemplate被忽略

我正在尝试设置DataGridCells的Validation.ErrorTemplate,这是xaml代码:

<Style x:Key="{x:Type DataGridCell}"  x:Uid="dataGridCellErrorTemplate" TargetType="{x:Type DataGridCell}">
    <Setter Property="Validation.ErrorTemplate">
        <Setter.Value>
            <ControlTemplate >
                <Border BorderBrush="Green" BorderThickness="2" ToolTip="Heidenei"></Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <!-- following line only for demonstration that the setter is working ... -->
    <Setter Property="Background" Value="Aquamarine"></Setter>              
</Style>
Run Code Online (Sandbox Code Playgroud)

当datagridcells的背景成功地变为绿色(与任何验证结果无关)时,使用的Validation.ErrorTemplate仍然是默认值,即红色边框。

我知道在stackoverflow中也有类似的问题,例如,设置 DataGridCell错误模板的样式, 但它们并不能真正解决我的问题。

任何帮助表示赞赏

坦率

validation wpf datagrid idataerrorinfo

6
推荐指数
1
解决办法
1971
查看次数

在自定义CellTemplate中继承WPF DataGrid样式

我希望在WPF数据网格中有一个自定义列类型,其中一部分将是用户输入的文本框.不幸的是,它似乎没有继承数据网格本身的外观 - 它不显示交替颜色,当选择或编辑一行时,相关单元格不会以相同方式突出显示,依此类推.

           <DataGridTemplateColumn Header="Name" >
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate >
                        <TextBox Text="{Binding DisplayName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" BorderThickness="0" />                          
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)

看起来默认文本框的样式会覆盖数据网格的样式; 有没有办法只使用datagrids风格?我当然可以设置文本框的样式以模仿数据网格,但如果我想添加其他控件,我也必须为每个控件执行此操作.如果我沿着那条路走下去,我将如何根据celltemplate中的datagridrow属性更改样式? - 例如IsSelected.

wpf xaml datagrid celltemplate

6
推荐指数
1
解决办法
955
查看次数

如何使隐式滚动查看器出现在左侧而不是右侧

当列表中有足够的对象时,我有一个ScrollViewer出现在右侧.如何让它出现在左侧?

<ListBox 
x:Name="MessageListBox" 
BorderThickness="0" 
ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
HorizontalContentAlignment="Stretch"  
AlternationCount="2" 
ItemContainerStyle="{StaticResource AltStyle}" 
SelectionMode="Extended" 
>
 <ListBox.ItemTemplate >
  <DataTemplate>
   <!-- button --> 
<!-- closing tags --> 
Run Code Online (Sandbox Code Playgroud)

wpf xaml

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

在运行时从WPF中的资源加载图像

我试图使用以下代码在WPF中运行时加载图像

_image = new Image();
BitmapImage src = new BitmapImage();
src.BeginInit();
src.UriSource = new Uri(@"pack://application:,,,/images/tagimages/placeholder.png", UriKind.Absolute);                
src.CacheOption = BitmapCacheOption.OnLoad;
src.EndInit();
_image.Source = src;
_image.Stretch = Stretch.None;
Run Code Online (Sandbox Code Playgroud)

在我的项目中,我有一个名为images的文件夹和一个名为tagimages的文件夹的子文件夹,其中包含placeholder.png.当我运行此代码时,我收到以下错误

"无法找到资源'images/tagimages/placeholder.png'"

我究竟做错了什么?

wpf

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

INotifyPropertyChanged用于静态变量

我有一个非静态变量,INotifyPropertyChanged成功实现.然后我尝试将其设为全局,因此将其变为静态变量.但这一次,INotifyPropertyChanged不起作用.有解决方案吗

c# wpf static inotifypropertychanged

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

如何在中间没有线条的情况下使刷子光滑

在此输入图像描述

大家好,正如你在之前的画笔中看到的那样,中间有线条,
如何使它平滑是不是很顺利?(如何删除那些行)我用混合创建它

<Grid x:Name="LayoutRoot">
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.452,1.962" StartPoint="1.164,-0.352">
                <GradientStop Color="#FF202020" Offset="0"/>
                <GradientStop Color="#FF545454" Offset="1"/>
            </LinearGradientBrush>
        </Grid.Background>
    </Grid>
Run Code Online (Sandbox Code Playgroud)

c# wpf blend

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

解决WPF应用程序的性能问题

我已经列出了所有可以帮助改善具有大量控件的非常复杂的应用程序中的性能的列表.如果你想加你的,欢迎你!

  • 如果您知道控件的大小,请删除"自动"并输入实际值,这样父级就不必解析所有子级以检查他需要的大小
  • 如果元素不需要是交互式的,则设置参数IsHitTestVisible = False
  • 冻结所有可能的对象
  • 使用静态资源而不是动态资源
  • 不要使用Ellipse对象,将Ellipse转换为Path
  • 如果可以使用TextBlock,请不要使用TextBox或Label
  • 尽可能使用Canvas而不是Grid
  • 没有FlowDocument
  • 虚拟化!VirtualizingStackPanel而不是StackPanel
  • 不要使用List,ObservableCollection更快
  • 使用Drawing库,它比Shapes库更快
  • 检查你的装订!如果绑定不起作用,则可能非常慢
  • 不要使用Visibility.Hidden,尽可能使用Visibility.Collapsed
  • DependencyProperty比INotifyPropertyChanged快3倍
  • StreamGeometry比PathGeometry快
  • 完成后清除事件处理程序!
  • 如果可以,请不要使用"对象不透明度"属性,使用其颜色不透明度
  • 检查您的应用程序是否为硬件渲染(第2层)
  • 尽可能减小图像的尺寸/质量
  • 渲染图像比渲染矢量更快!

我使用的工具:

  • WPF检查员
  • 史努比
  • WPFPerf套件
  • Visual Studio探查器
  • 适用于.NET的CLR Profiler

wpf performance blend

6
推荐指数
1
解决办法
1706
查看次数

更改WPF窗口的内容

当我单击导航栏上的按钮时,将打开一个新窗口.例如:

    private void btFinanzen_Click(object sender, RoutedEventArgs e)
    {
        Finanz mw = new Finanz(login);
        mw.Show();

    }
Run Code Online (Sandbox Code Playgroud)

现在,我不想在新窗口中显示它.而不是那样,我想让它显示在同一个窗口.我尝试了以下内容:

    private void btFinanzen_Click(object sender, RoutedEventArgs e)
    {
        Finanz mw = new Finanz(login);
        //mw.Show();
        this.Content = Finanz f;

    }
Run Code Online (Sandbox Code Playgroud)

但它失败了.我应该说的是,我现在有很多不同的窗口,希望它们全部显示在一个窗口 - 每个窗口都可以点击一个不同的按钮.我该怎么办呢?

c# wpf

6
推荐指数
1
解决办法
7519
查看次数