小编Din*_*esh的帖子

我可以在WPF中使用NotifyIcon吗?

我想使用WPF最小化应用程序到系统托盘."NotifyIcon"是实现这一结果的唯一方法吗?如果是,在WPF中使用"NotifyIcon"需要哪个命名空间?

如果可能使用"NotifyIcon",请提供一些提示,我如何在主窗口中使用它?

我的主窗口是,

public partial class MonthView : MetroWindow
{

    public DateTime SelectedDate { get; set; }

    public MonthView()
    {

            InitializeComponent();
            calMain.DisplayDate = DateTime.Today;
            Globals._globalController = new AppController();
            Globals._globalController.appTaskManager.setupLocal();
            Globals._globalController.setMonthViewWindow(this);

    }

    public void calItemSelectedDate(object sender, SelectionChangedEventArgs e)
    {
        DateTime d;
        if (sender is DateTime)
        {
            d = (DateTime)sender;
        }
        else
        {
            DateTime.TryParse(sender.ToString(), out d);
        }

        SelectedDate = d;

        ShowActivity(d);
     }

    public void ShowActivity(DateTime date)
    {
        DayView Activity = new DayView(date);
        Activity.Show();
        this.Hide();
    }

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

c# windows wpf notifyicon wpf-controls

12
推荐指数
3
解决办法
4万
查看次数

获取当前活动的应用程序名称

我想在计时器停止时获取当前活动应用程序的名称.录制20秒后,它应显示当前活动的应用程序名称.我尝试了一些代码.你可以在这里看到.但是在计时器停止后它没有向我显示任何内容.

C#代码:

public class Win32wrapper 
{
    private System.Timers.Timer pingTimer;
    private Timer recordTimer;

    private List<HarvestApp.ProcessInformation> ProcessList = new List<HarvestApp.ProcessInformation>();

    [DllImport("user32.dll")]
    public static extern IntPtr GetForegroundWindow();

    [DllImport("user32.dll")]
    public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint processId);

    private DateTime recordStartTime;

    public void startTimer(int pingTimerValue=5000, int recordTimerValue=20000)
    {

        pingTimer = new System.Timers.Timer(pingTimerValue);
        pingTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
        pingTimer.Interval = pingTimerValue;
        pingTimer.Enabled = true;

        recordTimer = new Timer(recordTimerValue);
        recordTimer.Elapsed += new ElapsedEventHandler(OnRecordEvent);
        recordTimer.Interval = recordTimerValue;
        recordTimer.Enabled = true;

        recordStartTime = DateTime.Now;
    }

    private void OnTimedEvent(object source, …
Run Code Online (Sandbox Code Playgroud)

c# wpf timer application-name

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

如何在wpf中使用DateTimePicker绑定

在我的wpf应用程序中,在CustomView窗口中,以下是我声明的属性,

private DateTime starttime 
    {
        get
        {
            return DateTime.Parse(StartTimeText.Text); 
        }
        set
        {
            StartTimeText.Text = value.ToString();
            OnPropertyChanged("starttime");
        } 
    }

    private DateTime stoptime
    {
        get
        {
            return DateTime.Parse(StopTimeText.Text);
        }
        set
        {
            StopTimeText.Text = value.ToString();
            OnPropertyChanged("stoptime");
        }
    }

protected virtual void OnPropertyChanged(String time)
    {
        if (System.String.IsNullOrEmpty(time))
        {
            return;
        }
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(time));
        }
    }

public event PropertyChangedEventHandler PropertyChanged;
Run Code Online (Sandbox Code Playgroud)

在xaml中,

<DatePicker x:Name="StartTimeText" 
            SelectedDate="{Binding Path=starttime}"  
            BorderThickness="0" 
            Background="Yellow"
            Width="100"/>

<DatePicker x:Name="StopTimeText" 
            SelectedDate="{Binding Path=stoptime, Mode=TwoWay}" 
            BorderThickness="0" 
            Background="Yellow"
            Width="60"/>
Run Code Online (Sandbox Code Playgroud)

通过这种方式,我在启动时和停止时间控件中获取日期.但我希望时间用"hh:mm tt"格式.WPF工具箱中没有DateTimePicker控件.所以为了获得指定格式而不是日期的时间,我该怎么办?请建议.

c# wpf xaml binding datepicker

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

绑定表达式错误:在对象上找不到属性

我在WPFappcation中使用DataBinding了一个comboBox.projectList中的ProjectName应该在我的内部添加comboBox,但是当我运行应用程序时,每次我都会收到这些错误;

System.Windows.Data错误:40:BindingExpression路径错误:'object'''DayView'(Name ='MainWin')'上找不到'projectList'属性.BindingExpression:路径= projectList; DataItem ='DayView'(Name ='MainWin'); target元素是'ComboBox'(Name =''); 目标属性是'ItemsSource'(类型'IEnumerable')System.Windows.Data错误:40:BindingExpression路径错误:'object'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' BindingExpression:路径= selectedProjectid; DataItem ='ComboBox'(Name =''); target元素是'ComboBox'(Name =''); target属性是'SelectedValue'(类型'Object')

我使用数据绑定的xaml代码是:

<DataTemplate x:Key="EditableDataTemplate">
            <StackPanel Orientation="Horizontal" Width="596">
                <TextBox Text="{Binding ClientNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/>
                <TextBox Text="{Binding ApplicationNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/>
                <TextBox Text="{Binding StartTimeBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/>
                <TextBox Text="{Binding StopTimeBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/>
                <TextBox Text="{Binding TaskNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/>
                <ComboBox x:Name="ComboBox2" ItemsSource="{Binding …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml binding-expressions

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

无法找到引用绑定的源'RelativeSource FindAncestor,AncestorType ='MahApps.Metro.Controls.Glow',AncestorLevel ='1''

我已经创建了一个wpf应用程序,我在其中使用了MahApps Metro工具作为我的视图窗口.我的应用程序运行正常,但输出窗口中显示绑定错误.我没有使用该错误中提到的任何代码.

错误是:

无法找到与引用'RelativeSource FindAncestor绑定的源,AncestorType ='MahApps.Metro.Controls.Glow',AncestorLevel ='1''.BindingExpression:路径= GlowColor; 的DataItem = NULL; target元素是'SolidColorBrush'(HashCode = 9047482); 目标属性是'颜色'(类型'颜色')

xaml代码:

<Controls:MetroWindow 
    x:Name="MainWin"
    x:Class="TimeSheet.DayView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:l="clr-namespace:TimeSheet.Views.DataTemplateSpace"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    Title="DayView" Width="596" Height="596">

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>

<DataTemplate x:Key="DefaultDataTemplate">
            <StackPanel Orientation="Horizontal" Width="596">
                <TextBox Text="{Binding ClientNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/>
                <TextBox Text="{Binding ApplicationNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/>
                <TextBox Text="{Binding StartTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/>
                <TextBox Text="{Binding …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml relativesource findancestor

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

如何使用属性更改TimePicker格式

我在使用扩展的wpf工具包的wpf应用程序中使用了TimePicker格式。我正在使用“ HH:MM”格式。但问题是,该按钮允许直接从选项中选择小时,显示24小时格式,但我只希望12小时。但是我通过将Endtime从“ 23:59”更改为“ 11:59”来通过TimePicker的属性进行管理。但是那些向上和向下按钮仍然显示小时数,最高为23。因此,如果我想将数字设为11,该怎么办?我只能通过TimePicker的属性来实现吗?也没有显示一天的一部分,即上午/下午。我还想要另一个按钮,该按钮应该向我显示这两个选项(即AM和PM)。请提出建议,我应该如何进行?

我绑定到我后面代码中的DateTime对象的Timepicker控件如下,

<Window x:Class="TimeSheet.CustomView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    x:Name="Time"
    Title="CustomView" Width="596" Height="596">
<Grid>
    <StackPanel Orientation="Horizontal" Height="30" Width="596" Margin="0,137,-8,399">
        <xctk:TimePicker x:Name="StartTimeText" Value="{Binding starttime, ElementName=Time, Mode=TwoWay}" BorderThickness="0" Background="Yellow" Width="113" EndTime="11:59:0" AllowSpin="False"/>
        <xctk:TimePicker x:Name="StopTimeText" Value="{Binding stoptime, ElementName=Time, Mode=TwoWay}" BorderThickness="0" Background="Yellow" Width="115" EndTime="11:59:0" AllowSpin="False"/>
    </StackPanel>              
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

我的窗口的用户界面-

在此处输入图片说明

c# wpf timepicker

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