我的应用程序在另一个线程的后台工作,以及后台线程填充此列表的列表中的Gui绘制结果
在初始化中我做了后台线程,当我在Gui按下按钮时,这个线程开始工作; 然后我点击另一个按钮来读取结果,而后台线程工作但GUI响应结果非常慢.
是否有任何解决方案我希望我的结果更快地在GUI上显示?
我的代码:
Thread startdrawingthread = new Thread(StartDrawing);
public MainWindow()
{
InitializeComponent();
}
private void bt_draw_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (ch_single.IsChecked == true || ch_entire.IsChecked == true)
{
currentMode = "";
startdrawingthread.Start();
//StartDrawing();
real_area.DrawingArea.Children.Clear();
real_area.DrawGrid(20);
}
}
private void bt_single_next_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (GlobalV.isfinished == false)
{
while (true)
{
if (GlobalV.Attatched_Elements.Count > 0)
{
try
{
real_area.DrawingArea.Children.Clear();
real_area.DrawGrid(20);
real_area.DrawElement(GlobalV.Attatched_Elements[i]);
i++;
}
catch
{
}
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
每次点击一个按钮时,我都试图在App.xaml中为两个以前定义的样式切换多个按钮.我尝试了一个通用的事件处理程序但它会显示错误'button_Click'的重载与委托'Windows.UI.Xaml.RoutedEventHandler'匹配.我相信它与签名有关,但无法解决它.这是MainPage.xaml.cs中实现的方法
public void button_Click(object sender, EventArgs e)
{
var button = (Button)sender;
if (button.Style != myButtonStyle)
button.Style = myButtonStylePressed;
else
button.Style = myButtonStyle;
}
Run Code Online (Sandbox Code Playgroud)
这是在一个按钮示例中在MainPage.xaml中实现的方式.
<Button Name="Row5Col4"
Grid.Row ="5"
Grid.Column ="4"
Margin="10, 10, 10, 10"
Height="10"
Width="10"
HorizontalAlignment="Left"
BorderThickness="0"
Style="{StaticResource myButtonStyle}"
Click="button_Click"
>
</Button>
Run Code Online (Sandbox Code Playgroud)
重要提示:有些人建议使用MouseClick而不是Click,但这不起作用,因为它是WP应用程序.我很感激你的到来.
根据Visual Studio导致错误的行是这一行 Click ="button_Click"
我正在尝试使用 c# 编码设置媒体元素的来源(视频位于项目的资产文件夹中),我的编码如下:
//Defined as such in my XAML
mediaElement.Source = new Uri(@"Assets\HarlemCampus.wmv");
mediaElement.Play();
Run Code Online (Sandbox Code Playgroud)
...但是当我单击按钮播放视频时收到以下错误:
我不想在 XAML 中预设源,因为我想根据用户在运行时选择的单选按钮动态更改媒体元素的源,如果有办法做到这一点?
如何在wpf中清除画布的内容?尝试canvas.clear()不起作用.另外如何在wpf应用程序中添加缩放控件?使用滚动条缩放以移动图像.
任何帮助是极大的赞赏
我已经看过其他类似的问题,但是他们似乎总是在XAML中这样做,因为这是在事件处理程序中,所以我需要找出c#中的答案。基本上,我只需要发送菜单项闪烁红色即可。
ColorAnimation ca = new ColorAnimation()
{
From = Color.FromRgb(0, 0, 0),
To = Color.FromRgb(255,0,0),
AutoReverse = true,
RepeatBehavior = new RepeatBehavior(3),
Duration=new Duration(TimeSpan.FromSeconds(.5))
};
(sender as MenuItem).Foreground.BeginAnimation(SolidColorBrush.ColorProperty, ca);
Run Code Online (Sandbox Code Playgroud) 我使用C#和XAML,我的主页开头如下:
<Page
x:Class="MyApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Height="754" Width="1018" MaxHeight="754" MaxWidth="1018" MinHeight="754" MinWidth="1018"
mc:Ignorable="d">
<Grid>
(...)
</Grid>
Run Code Online (Sandbox Code Playgroud)
但是当我启动应用程序时,窗口总是最大化.只有网格尊重XAML中提到的大小.我在这个论坛上读到了一些答案,但是当我写作时我遇到了编译错误:
ResizeMode="NoResize"
Run Code Online (Sandbox Code Playgroud)
在XAML代码中,或
Application.Current.MainWindow.Height = 754;
Run Code Online (Sandbox Code Playgroud)
在C#代码中(因为Application.Current是已知的,但不是Application.Current.MainWindow).
我无法弄清楚为什么这些解决方案对我不起作用.我也能看到这个:
WindowState="Maximized"
ResizeMode="NoResize"
WindowStyle="None"
Run Code Online (Sandbox Code Playgroud)
它也不起作用:"它在上下文中不存在".怎么了 ?
我的视图模型有一个 PointCollection 属性,如下所示:
public class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private PointCollection points;
public PointCollection Points
{
get { return points; }
set
{
points = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Points)));
}
}
}
Run Code Online (Sandbox Code Playgroud)
这通常显示为折线:
<Polyline Points="{Binding Points}" Stroke="Black" StrokeThickness="2"/>
Run Code Online (Sandbox Code Playgroud)
我如何有效地将其显示为单独圆圈的集合?
它可以很好地通过具有例如在其 ItemTemplate 中具有 EllipseGeometry 的 Path 元素的 ItemsControl 来完成,但是这将涉及大量 UI 元素,这对于 PointsCollection 中的大量点来说可能表现不佳。
我希望能够将列中的文本和一列的单元格居中。这是我到目前为止所拥有的 XAML。我不知道如何针对一项而不是所有项来做到这一点。
<ListView
Grid.Column="0"
Margin="3,3,0,3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Visible"
SelectionMode="Single">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridView.Columns>
<GridViewColumn Width="100" DisplayMemberBinding="{Binding CopiedFrom}">
<GridViewColumn.Header>
<GridViewColumnHeader>Copied From:</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
<GridViewColumn Width="100" DisplayMemberBinding="{Binding Name}">
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</GridViewColumn.HeaderContainerStyle>
<GridViewColumn.Header>
<GridViewColumnHeader>Date/Time:</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)
对 XMAL 来说还很陌生。任何帮助将不胜感激。
我有一个 win32 应用程序(我称之为 win32#1),我在我的 uwp 应用程序下创建了一个 Win32 文件夹,并将我的 win32 应用程序的可执行文件复制到这个文件夹中,我还修改了 Package.appxmanifest 以包含我的 win32 应用程序。然后我可以使用 FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync() 来启动我的 win32 应用程序。我这样做了:
private async Task<bool> LaunchWin32Number1()
{
try
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
return true;
}
catch (Exception)
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有另一个 win32 应用程序,我称之为 win32#2,有没有办法可以在我的 uwp 应用程序中同时启动 win32#1 和 win32#2?例如,在 uwp 中单击按钮 1 我将启动 win32#1,在 uwp 中单击按钮 2 我将启动 win32#2。
我想知道这是否可行,然后如果有人可以向我指出一些文件或示例如何做到这一点,我真的很感激。
或者,如果唯一的方法是 uwp 启动一个 win32 应用程序#0,那么让 win32#0 启动 #1 或 #2。
请帮我画一个厚度为 2 的圆。我能够画一个实心圆(代码如下)。如何使其不填充厚度为2?
M 0,0 A 180,180 180 1 1 1,1 Z
Run Code Online (Sandbox Code Playgroud)