我知道并使用两种方法来存储和访问应用程序范围上的资源:
这两种方法在性能和复杂性方面有什么区别,何时应该使用每种方法以及如何在WPF和VB或C#代码中以最佳方式消耗资源?
提前致谢,
朱利安
当我画这样的东西时(这里只是随机图纸):
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DrawingVisual visual = new DrawingVisual();
DrawingContext context = visual.RenderOpen();
Pen pen = new Pen(Brushes.Black, 1);
context.DrawEllipse(Brushes.YellowGreen, pen, new Point(0,0), 40, 40);
for (int i = 0; i <= 100 - 1; i++)
context.DrawLine(new Pen(Brushes.Black, 1), new Point(0, i), new Point(i, i));
context.Close();
RenderTargetBitmap bmp = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Pbgra32);
bmp.Render(visual);
image1.Source = bmp;
}
}
Run Code Online (Sandbox Code Playgroud)
DrawLine和DrawEllipse混合的颜色.(我发现只有DrawLine才使用笔,而不是像Rectangle和Ellipse这样使用Brush的其他形式).奇怪的是,即使是基础网格背景(argh)的LinearGradientBrush的颜色. 我希望它们是z-Ordered,每个都具有完全不透明度.
这里是XAML代码:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"> …Run Code Online (Sandbox Code Playgroud) 我是VB.NET中的专业Windows应用程序开发人员和Windows窗体的C#,现在非常兴奋能够进入WPF开发阶段.这是我的第一个问题,我无法通过搜索解决:
我编写了以下模板来完全改变我的按钮的外观:
<ControlTemplate TargetType="{x:Type Button}" x:Key="ImageButtonTemplate">
<Grid>
<Image Name="img" Source="/PSPlayer;component/Images/Buttons/ButtonNormal_normal.png"/>
<ContentPresenter Stylus.IsTapFeedbackEnabled="False" Stylus.IsTouchFeedbackEnabled="False" Stylus.IsPressAndHoldEnabled="False" Stylus.IsFlicksEnabled="False" Width="98" Height="61"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="img" Property="Source" Value="/PSPlayer;component/Images/Buttons/ButtonNormal_MouseOver.png"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="img" Property="Source" Value="/PSPlayer;component/Images/Buttons/ButtonNormal_MouseDown.png"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
这里有一个按钮定义:
<Button Content="SomeText" Height="61" Margin="0,0,0,7" Name="button7" Width="98" Click="button7_Click" Template="{StaticResource ImageButtonTemplate}"/>
Run Code Online (Sandbox Code Playgroud)
问题是,文本"SomeText"出现在按钮的左上角,我无法更改该位置.按钮的属性HorizontalContentAlignment和VerticalContentAlignment不显示效果(我想知道为什么).
另外,我想有时将文本定位到某个位置,例如x = 70,当背景图像中有一个位于左侧的符号,直到x = 60.
我在按钮内嵌了一个标签,我可以定位,但认为必须有一个更清洁的解决方案.
希望我清楚自己.WPF规则顺便说一句 - 以及这个网站,我解决的大多数问题都来自这里(来自谷歌):)
提前致谢,
朱利安