Tag: xaml

如何调整C#WPF程序的大小以适应任何屏幕分辨率

我试图找出如何调整我的C#WPF程序的大小,以基本适合任何屏幕分辨率。 我正在尝试将我的程序安装到屏幕分辨率为1280 x 1024的计算机上。 我找不到任何关于如何准确执行此操作的信息,当然我可以根据特定的屏幕来安装程序的尺寸,但每台计算机的屏幕分辨率可能会有所不同吗? 我尝试使用此处提供的显而易见的解决方案: 根据屏幕分辨率调整WPF窗口和内容的大小,但它根本没有帮助。 即我用过:(另外,我不确定是否需要将HorizontalAlignment和VerticalAlignment设置为“拉伸”,但我还是做了。) Title=”my screen” Height=”{Binding SystemParameters.PrimaryScreenHeight}” Width=”{Binding SystemParameters.PrimaryScreenWidth}” WindowStartupLocation=”CenterScreen” WindowState=”Maximized”> … 每当我在尺寸为1280 x 1024的计算机上运行我的exe时,它会切断我网格中的内容。 任何建议或帮助都会很棒,甚至链接到示例都会很棒。 提前致谢。

Windows Phone 8 – 如何在地图上显示当前位置

正如标题所示,我正在努力在地图上显示用户的当前位置。 Afaik有两种显示当前用户位置的方法: 在代码中:创建一个椭圆,将其设置为MapOverlay内容,设置MapOverlay的GeoCoordinate,将此叠加层添加到MapLayer并将其添加到地图中 – 但我无法再访问MapOverlay ,因此我无法更改(更新)用户的位置。 有没有办法更新用户位置而不必重绘所有地图图层? XAML和代码:在Windows Phone 7中,我能够将一个Pushpin添加到地图中,让GeoCoordinateWatcher处理PositionChanged事件并将MyLocation.Location设置为当前位置。 如果您不使用Windows Phone Toolkit,似乎无法将Pushpin添加到地图中。 所以我尝试从Windows Phone Toolkit添加Pushpin : xmlns:maps=”clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps” xmlns:maptk=”clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit” 但我无法访问MapPage.xaml中的MyLocation图钉(调试器表示它为null )。 我可以使用maptk:Pushpin在地图上显示和更新当前用户位置吗? 在Windows Phone 7中,我可以简单地为图钉创建一个XAML布局,该布局将保存用户位置,如下所示: xmlns:maps=”clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps” 然后我可以添加一个GeoCoordinateWatcher来监听PositionChanged事件并更改MyLocation图钉的Location : void GeoCoordinateWatcher_PositionChanged ( object sender, GeoPositionChangedEventArgs e ) { MyLocation.Location = e.Position.Location; }

ControlTemplate for ScrollBar仅适用于DataGrid

你好我有一个ScrollBar模板如下 – 只显示相关部分: <Border…. 现在矩形部分: 我只希望它出现在DataGrids上或者我希望这个进入ControlTemplate只能在DataGrids的ScrollBars上运行。 任何帮助将不胜感激! 谢谢!

WPF在异步文件复制期间显示进度条

我是一个wpf newb所以这个问题可能是微不足道的。 我正在尝试将文件从一个文件夹复制到另一个文件夹。 我想在复制过程中显示进度条。 我的代码是这样的: if (!System.IO.File.Exists(basemapDest)) { await Copier.CopyFiles(new Dictionary { {basemapSrc, basemapDest}, }, prog => prgBaseMap.Value = prog); } public static class Copier { public static async Task CopyFiles(Dictionary files, Action progressCallback) { for (var x = 0; x < files.Count; x++) { var item = files.ElementAt(x); var from = item.Key; var to […]

默认样式不适用于子类

我有一个奇怪的场景涉及覆盖WPF中的默认样式并将它们应用于子类。 这不可能吗? 例如,我有以下代码: This should be red. This should be red. This should be blue. This should be blue. 有了这个代码隐藏: namespace TestWPFStyling { public partial class MainWindow : Window { } public class SomeLabel : Label { } public class YellowLabel : SomeLabel { } } 我希望StackPanel中的控件YellowLabel颜色为蓝色,外部颜色为红色,但两者都是黑色。 子类是否有办法采用其父类的默认样式?

如何在WPF中重新加载(重置)整个页面?

我有Request.xaml按钮和许多comboxes,所以我想重新加载它并将combox值置于按钮点击后将其设置为默认值。 我当然会做更多的工作人员。 我的Request.xaml代码包含以下部分代码: 另外,xaml代码这样的事件 而Request.xaml.cs文件只有private void Button_Click(object sender, RoutedEventArgs e)函数。 我以这种方式显示Request.xaml :首先, MainWindow.xaml显示MainPage.xaml , ,最后是MainPage.xaml dispays Request.xaml 是否可以重置整个页面,因为我需要让用户有机会将新请求的参数添加到现有参数中,最终将位于.xml文件中? 也许可以通过OnNavigatedTo方法或UIElement.InvalidateVisual方法实现 ( http://msdn.microsoft.com/en-us/library/system.windows.uielement.invalidatevisual.aspx )

使用xaml在windws 8应用程序中从页面导航到另一个时添加进度条

我正在开发一个Windows 8应用程序,我想在从一个导航到另一个页面时向我的页面添加一个进度条,因为用户必须等待才能从服务器加载数据。 任何人都可以向我提供我需要在XAML和C#中添加的代码吗? 应该使用进度条的哪些属性或事件? // XAML PAGE <!– –> //C# Page using App1.Data; using App1.DataService; using System; using System.Collections.Generic; using System.IO; using System.Linq; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; // The Grouped Items Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234231 namespace App1 { […]

如何将用户控件放在文档查看器中?

是否可以将用户控件放在面板中? 如果可能的话,那将是怎样的?

WPF窗口位于顶部/左侧放置任务栏的最大化状态

我正在研究WPF应用程序,我遇到的问题是,当WindowStyle=None和WindowState = WindowState.Maximized ,应用程序位于顶部或左侧放置任务栏。 任务栏放置在底部或右侧时,一切正常。 我知道窗口的Left和Top属性,但它们在Maximized状态下被忽略。 还有Microsoft.Windows.Shell.WindowСhrome ,它提供了拖动,双击以最大化和恢复,捕捉和取消隐藏的function。 (需要添加为dll参考) 我希望实现我的应用程序不隐藏或进入任务栏,并正确使用WindowСhrome提供的行为。 MainWindow.xaml MainWindow.xaml.cs using System.Windows; namespace WpfAppTestFullScreen { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight; MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth; } private void FullScreenButton_Click(object sender, RoutedEventArgs e) { if (WindowState == WindowState.Maximized) { WindowState […]

如何在不同的控件类型中实现依赖项属性值inheritance

A有一组我正在创建的自定义控件,每个控件都有各自控件的基类。 因为它们各自具有不同的基本控件,所以它们不能共享完全相同的依赖项属性。 是否可以将依赖属性链接在一起,以便它们可以相互级联? (不确定我是否正确使用术语级联语法) public class RCTWindow : ContentControl { public static readonly DependencyProperty RemapColorProperty = DependencyProperty.RegisterAttached( “RemapColor”, typeof(RemapColors), typeof(RCTWindow), new FrameworkPropertyMetadata( RemapColors.SeaGreen, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnVisualChanged))); //… } public class RCTButton : Button { public static readonly DependencyProperty RemapColorProperty = DependencyProperty.RegisterAttached( “RemapColor”, typeof(RemapColors), typeof(RCTButton), new FrameworkPropertyMetadata( RemapColors.SeaGreen, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnVisualChanged))); //… […]