小编use*_*256的帖子

ItemsControl与其项目源 - WPF Listbox不一致

我有一个WPF窗口,其中包含一个ListBox控件,该控件在执行按钮单击方法时填充.

XAML:

<ListBox Name="ThirdPartyListBox" ItemsSource="{Binding}" Margin="0,70,0,0">                      
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="C:\Users\Test\Desktop\Project\ACME-WPF\ACME-WPF\window-new-3.ico" Margin="5" Width="50"/>
                                <Button Name="ThirdPartyInstallButton" Content="Install" Click="InstallThirdPartyUpdatesButton_Click" Margin="5,5,0,0" Height="25"></Button>
                                <Button Name="ThirdPartyPostoneButton" Content="Postpone" Click ="PostponeThirdPartyUpdatesButton_Click" Margin="5,5,0,0" Height="25"></Button>
                                <TextBlock FontWeight="Bold" Text="{Binding Item2.Name}" Margin="12,25,0,0"/>
                                <TextBlock FontWeight="Bold" Text="{Binding Item2.RequiredVersion}" Margin="3,25,0,0"/>
                                <TextBlock Text="{Binding Item2.CustomUIMessage}" Margin="10,25,0,0" TextWrapping="Wrap" Foreground="Red"/>
                                <TextBlock Text="You have used " Margin="3,25,0,0"/>
                                <TextBlock Text="{Binding Item3.UsedDeferrals}" Margin="3,25,0,0"/>
                                <TextBlock Text=" of " Margin="3,25,0,0"/>
                                <TextBlock Text="{Binding Item2.MaxDefferals}" Margin="3,25,0,0"/>
                                <TextBlock Text=" deferrals for this update." Margin="3,25,0,0"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
Run Code Online (Sandbox Code Playgroud)

C#:

 private void CheckforThirdPartyUpdatesButton_Click(object sender, RoutedEventArgs e) …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml listbox

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

链接到WPF应用程序中的默认电子邮件处理程序中的打开新电子邮件

我的目标是基本的:在WPF表单上有一个标签/ texblock,你有一个风格化看起来像一个链接.单击时,控件应在用户的默认电子邮件应用程序中打开一个新的电子邮件撰写窗口.实际打开新电子邮件窗口的代码似乎微不足道:

Process.Start("mailto:example@stackoverflow.com?subject=SubjectExample&body=BodyExample ");
Run Code Online (Sandbox Code Playgroud)

但是我遇到两件事有问题:

  1. 将"新消息打开"操作绑定到标签单击事件.
  2. 对标签进行样式化,使其看起来与默认的WPF超链接完全相同.

c# email wpf

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

WPF中的列表框分隔符和最终分隔符的省略

我有两件事我想要实现:

  1. 在WPF中的列表框项之间添加水平分隔符.
  2. 不要在最终列表框项的底部显示分隔符.

我目前的布局如下图所示:

在此输入图像描述

这显示了2个列表框项目(虽然我无法知道可能生成多少项目).我希望它们用水平分隔符分隔,除了最后一个列表框项目,因此窗格底部没有备用分隔符.我怎样才能在XAML中实现这一目标?在这里查看我当前的XAML:

 <TabItem Header="Third Party Updates">
            <Grid>
                <TextBlock Name="ThirdPartyNoManifestTextBox" Width="Auto" HorizontalAlignment="Left" Margin="267,22,0,0" TextWrapping="Wrap" Text="{Binding Path=WindowsUpdateCompliance, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" FontSize="14" Foreground="DarkSlateBlue"/>
                <Button Name="CheckforThirdPartyUpdatesButton" Content="Check for Third Party Updates" Margin="10,11,339,304" Click="CheckforThirdPartyUpdatesButton_Click" MaxWidth="200" Grid.Column="1" Grid.Row="1"/>
                <ListBox Name="ThirdPartyListBox" ItemsSource="{Binding}" Margin="0,70,0,0">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Button Name="ThirdPartyInstallButton" Content="Install" Click="InstallThirdPartyUpdatesButton_Click" Margin="5,5,0,0" Height="25"></Button>
                                <Button Name="ThirdPartyPostoneButton" Content="Postpone" Click ="PostponeThirdPartyUpdatesButton_Click" Margin="5,5,0,0" Height="25"></Button>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <Label Content="•" Grid.Row="1" VerticalContentAlignment="Center"/>
                                    <Label Content="•" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml listbox

7
推荐指数
1
解决办法
2858
查看次数

WPF 按钮 IsEnabled 检查多个绑定

我目前配置了以下数据绑定的 XAML 按钮的 IsEnabled 属性:

<Button Name="ThirdPartyPostoneButton" Content="Postpone"
        Click ="postponeThirdPartyUpdatesButton_Click" Margin="5,5,0,0"
        Height="25" IsEnabled="{Binding Item3.CanDefer}"/>
Run Code Online (Sandbox Code Playgroud)

我还需要添加一个检查IsEnabled="{Binding Item3.InstallSourceExists}"(换句话说,必须满足两个条件才能启用按钮)。我怎样才能做到这一点?

c# wpf

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

Inserting Delimiter into PowerShell Output

The result of Get-Process -Name explorer | select Handles,WS,CPU,Id,ProcessName | ft -HideTableHeaders returns the following output:

2623 255336448 178.125 10080 explorer 
Run Code Online (Sandbox Code Playgroud)

In order to ingest this data into a third party system, I need to pipe delimit the result as such:

2623|255336448|178.125|10080|explorer 
Run Code Online (Sandbox Code Playgroud)

What is the best way to achieve this?

powershell

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

连接 Select-Object 语句中的两个属性

我正在选择已安装应用程序的 DisplayName 和 DisplayVersion 属性,如下所示:

$response = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Where-Object {$_.DisplayName -like '*My Application*'} | Select-Object DisplayName, DisplayVersion | ft -HideTableHeaders
Run Code Online (Sandbox Code Playgroud)

结果是:My Application 1.2

为了额外的解析目的,我需要将结果与管道字符连接起来,以便它返回为:My Application|1.2

但是我无法找到正确的语法。

powershell

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

从代码关闭材质设计DialogHost

我正在尝试找到一种方法来从代码启动活动DialogHost的关闭,但是无法找到正确的语法。我认为主要的挑战是从背后MainWindow代码之外的类访问DialogHost。

我的整个XAML:

<Window x:Class="MaterialDesignTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:MaterialDesignTest"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    TextElement.Foreground="{DynamicResource MaterialDesignBody}"
    TextElement.FontWeight="Regular"
    TextElement.FontSize="13"
    TextOptions.TextFormattingMode="Ideal" 
    TextOptions.TextRenderingMode="Auto"        
    Background="{DynamicResource MaterialDesignPaper}"
    FontFamily="{DynamicResource MaterialDesignFont}">

<materialDesign:DialogHost Identifier="RootDialog" Loaded="DialogHost_Loaded">
    <Grid>
        <StackPanel>
            <Button Width="100" x:Name="SearchRestore" Margin="0 150 0 0" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}" materialDesign:DialogHost.DialogClosingAttached="SearchRestore_OnDialogClosing" 
                Content="Restore" Click="SearchRestore_Click">
                <Button.CommandParameter>
                        <StackPanel Margin="10">
                            <TextBlock Text="Restoring..."/>
                        <Button Name="CircleButton" Margin="0 50 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}"
                        Command="{Binding SaveComand}" IsHitTestVisible="False"
                        materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding IsSaving}"
                        materialDesign:ButtonProgressAssist.Value="{Binding SaveProgressButton}">
                            <materialDesign:PackIcon Height="24" Width="24" Foreground="White">
                                <materialDesign:PackIcon.Style>
                                    <Style TargetType="materialDesign:PackIcon" BasedOn="{StaticResource {x:Type materialDesign:PackIcon}}">
                                        <Setter Property="Kind" Value="CloudSync" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsSaveComplete}" Value="True"> …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml material-design-in-xaml

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

简单闪烁文字

我试图将闪烁的“ Hello World”文本与C#/ WPF中可能的代码最少的简单演示项目放在一起。我编写的内容可以编译并运行,但实际上不会使文本闪烁(它基于一个计时器,该计时器每2秒触发一次并更改标签的可见性。有关文本为何不闪烁或有什么效率更高的任何想法)方法将是?代码:

using System;
using System.Timers;
using System.Windows;

namespace BlinkingText
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        static Timer _timer;
        static MainWindow window = new MainWindow();

    public MainWindow()
    {
        InitializeComponent();

        Start();
    }

    public static void Start()
    {
        var timer = new Timer(2000);
        timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
        timer.Enabled = true;
        _timer = timer;
    }

    public static void _timer_Elapsed(object sender, ElapsedEventArgs e)
    {

        if (window.HelloWorldLabel.Visibility == Visibility.Hidden)
        {
            Application.Current.Dispatcher.Invoke((Action)delegate
            { …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

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

向List <Tuple>添加了元素

我有一个List定义如下:

List<Tuple<string, long, DateTime>> firefoxBookmarkPaths = new List<Tuple<string, long, DateTime>>();
Run Code Online (Sandbox Code Playgroud)

但是我在添加到我的列表时遇到问题:

List<Tuple<string, long, DateTime>> firefoxBookmarkPaths = new List<Tuple<string, long, DateTime>>();

long fileSize = 0;
string bookmarkFile = null;
string directoryToCheck = null;
DateTime fileModifiedDate = DateTime.MinValue;

foreach (var dir in basePersistDirectories)
{
    directoryToCheck = dir + @"\C\Users" + @"\" + Environment.UserName + @"\" + @"AppData\Roaming\Mozilla\Firefox\Profiles";
    if (Directory.Exists(directoryToCheck))
    {
        var subDirectories = Directory.GetDirectories(directoryToCheck);
        foreach (var directory in subDirectories)
        {
            bookmarkFile = directory + @"\places.sqlite";

            if (File.Exists(bookmarkFile))
            {
                fileSize = new FileInfo(bookmarkFile).Length; …
Run Code Online (Sandbox Code Playgroud)

.net c#

0
推荐指数
1
解决办法
47
查看次数

标签 统计

c# ×7

wpf ×6

xaml ×4

listbox ×2

powershell ×2

.net ×1

email ×1

material-design-in-xaml ×1