我很难获得多个视图来对抗1个viewmodel.我已经阅读了多视图支持的命名约定而没有从中获得太多的东西,并且在此过程中尝试了无数的东西.
举个简单的例子吧.假设我有一个驻留在ShellViewModel中的ViewModel,它基本上包含Person对象列表.我想在我的应用程序中以两种不同的方式显示它们.

在这种情况下命名视图的正确方法是什么,以及如何在ShellView中显示两个视图?
我有一个像这样的网格:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0">Row 0, Column 1</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0">Row 1, Column 1</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0">Row 2, Column 1</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="0">Row 3, Column 1</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Grid.RowSpan="4">Column 1</TextBlock>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我不会在实际应用程序中实际使用TexBlocks,我用它们来使示例更容易.基本上我想设置从第1列中删除第0列中所有内容的边框.
你是怎样做的?
是否可以通过XAML为wpf实现if条件,如果是,请提供if条件以检查xaml中的.net框架版本.
我正在为Visual Studio 2010和2008分享xaml,我想为vs2010执行特定的代码片段并为vs2008隐藏相同的代码片段
我已经阅读了将模型数据中的更改传递给视图模型的各种方法.有人建议模型应尽可能实现INotifyPropertyChanged,以便它可以通知视图模型已更改的属性.一些建议在模型和视图模型之间建立服务层,服务层实现INPC,方法调用通过此服务层路由到模型,以便服务层通知视图模型.
我认为后者是对前者的更细粒度的修订,并且已经开始在我的模型类中实现INPC.这感觉不对,因为
a)我现在必须在视图模型中编写一个事件处理程序,用于模型中的通知.这采用长开关(propertyName)的形式,它在视图模型上设置相应的属性,导致NPC再次向上发送.我觉得我在这里写了很多锅炉板代码.
b)视图模型现在通过一串字符串耦合到我的模型,这些字符串仅由约定规定,即没有定义"接口".更不用说这会导致IDE的困难.
c)我的模型必须进行修改以适应这种情况!如果由于某种原因被关闭怎么办?我认为这样的模式旨在增加代码的可重用性和关注点的分离.不仅如此,而且触发INPC事件所需的代码是繁琐且重复的,并且不是真正可抽象的.
我真的很想知道WPF专业人员如何通过依赖属性等来解决这个问题.我感觉我错过了一些东西.我并不热衷于使用一个框架,因为我想从头开始学习.我已经离开WPF一两年了,最近和AngularJS一起工作让我质疑我的方法.
谢谢!
我有一个Wpf应用程序,我希望它部署在远程服务器上.以前我使用过VS2010,所以很容易创建setup/.msi文件并在其他机器上部署.
目前我有VS2012.它没有设置部署选项.另外,我阅读了有关部署应用程序的clickonce应用程序部署方法.
我尝试了一种方法,但它没有在本地本身正确安装应用程序.应用程序快捷方式首次启动应用程序(很少第二次启动).下次,它会抛出我的异常
"Cannot start application". Application cannot be started. Contact the application vendor
Run Code Online (Sandbox Code Playgroud)
错误详情如下:
ERROR DETAILS
Following errors were detected during this operation.
* [29-01-2014 11:32:48] System.Deployment.Application.DeploymentException (Activation)
- Activation failed.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.ComponentStore.ActivateApplication(DefinitionAppId appId, String activationParameter, Boolean useActivationParameter)
at System.Deployment.Application.SubscriptionStore.ActivateApplication(DefinitionAppId appId, String activationParameter, Boolean useActivationParameter)
at System.Deployment.Application.ApplicationActivator.Activate(DefinitionAppId appId, AssemblyManifest appManifest, String activationParameter, Boolean useActivationParameter)
at System.Deployment.Application.ApplicationActivator.ProcessOrFollowShortcut(String shortcutFile, String& errorPageUrl, TempFile& deployFile)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& …Run Code Online (Sandbox Code Playgroud) 这篇MSDN文章清楚地描述了安装WPF Performance Suite的过程,但对Windows 8.1用户提出了一个巨大的警告.
处理:
所以,这是我的一些问题:
这太烦人了,让我发疯了.
我使用C#编写了一个小的WPF小部件,它显示当前的CPU活动,使用的RAM和磁盘活动,作为三个小百分比类型的条形图.我已经使用了以下PerformanceCounters :( diskCounter PerformanceCounter返回当前的总磁盘活动,以每秒字节数为单位)
private void InitialisePerformanceCounters()
{
cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
totalRam = (int)(new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory / 1024 / 1024);
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
diskCounter = new PerformanceCounter("PhysicalDisk", "Disk Bytes/sec", "_Total", true);
}
Run Code Online (Sandbox Code Playgroud)
问题是虽然我已经发现如何获得总可用RAM来计算使用的百分比,但我无法找到如何读取磁盘的"理论"最大数据传输速率.我需要这个来计算使用的磁盘传输速率的百分比.任何帮助将不胜感激.
我有一种情况,我试图为动态加载的控件设置Tab键顺序(tabindex).主要的XAML看起来像这样:
<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding ItemsDataSource}" Name="overlayItems" ItemTemplate="{StaticResource DetailsTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
例如,假设DetailsTemplate是这样简单的:
<DataTemplate x:Key="DetailsTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="22" />
<RowDefinition Height="22" />
<RowDefinition Height="22" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" Padding="0">Field 1</Label>
<TextBox Grid.Column="1" Grid.Row="0" Name="field1TextBox" TabIndex="0" Text="{Binding Field1Value}"/>
<Label Grid.Column="0" Grid.Row="1" Padding="0">Field 2</Label>
<TextBox Grid.Column="1" Grid.Row="1" Name="field2TextBox" TabIndex="1" Text="{Binding Field2Value}"/>
<Label Grid.Column="0" Grid.Row="2" Padding="0">Field 3</Label>
<TextBox Grid.Column="1" Grid.Row="2" Name="field3TextBox" TabIndex="2" Text="{Binding Field3Value}"/>
</Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
除了生成的Tab键顺序之外,此XAML工作正常.
假设ItemsDataSource是类的集合并包含该类的3个实例,则创建三组DetailsTemplate数据模板.但是Tab键顺序没有改变,每个field1TextBox都保留在TabIndex 0.这意味着,而不是从field1TextBox的第一个实例到field2TextBox到field3TextBox的Tab键,选项卡从field1TextBox的第一个实例转到field1TextBox的第二个实例然后到field1TextBox的第三个实例然后到field2TextBox的第一个实例,依此类推.我的问题是,如何更正标签顺序,例如,数据模板的第二个实例将其文本框标签索引分别更新为3,4和5?
我创建了一个生成Code 39条形码的测试应用程序.问题是当我在屏幕上显示条形码时,它会模糊或被撕裂.如果我使用BitmapScalingMode其他任何东西NearestNeighbor,我会得到模糊的条形码.当我使用时NearestNeighbor,我得到如下所示的斜线斜线.对角线仅在我调整窗口大小时出现.(如果我停在正确的位置,它会停留在那里.)图像本身不会改变大小,而是在我调整窗口大小时在屏幕上移动.
我也尝试过使用RenderOptions.EdgeMode="Aliased",但它似乎没有任何影响......
撕裂/模糊/正确

WPF示例代码:
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,50,0,0">
<Image x:Name="imgBarcode" Stretch="Fill" RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Aliased" />
</Border>
Run Code Online (Sandbox Code Playgroud)
图像生成:
imgBarcode.Source = loadBitmap(c.Generate(barcodeText.Text));
imgBarcode.Width = c.GetWidth();
imgBarcode.Height = c.GetHeight();
Run Code Online (Sandbox Code Playgroud)
样本生成代码:
Bitmap bmp = new Bitmap(width, height);
using (Graphics gfx = Graphics.FromImage(bmp))
using (SolidBrush black = new SolidBrush(Color.Black))
using (SolidBrush white = new SolidBrush(Color.White))
{
// Start the barcode:
addBar(gfx, black, white, '*');
foreach (char c in barcode)
{
addCharacter(gfx, black, white, c);
} …Run Code Online (Sandbox Code Playgroud) 我使用 MVVM 编写了一个大型 WPF 应用程序,但它遇到了一些间歇性问题。我最初询问“已添加具有相同键的项目”从代码问题中选择 ListBoxItem 的异常,这解释了问题,但没有得到答案。
一段时间后,我设法找出了Exception我得到的原因,并将其记录在没有不可变字段的类中重写 Object.GetHashCode() 时返回什么?问题。基本上,这是因为我在公式中使用了可变字段来返回 的值GetHashCode。
从我收到的针对该问题的非常有用的答案中,我设法加深了对该领域的理解。以下是三个相关规则:
这些规则影响了我对不知道从GetHashCode方法返回什么的问题的可能解决方案:
readonly为每个类创建一个附加字段,而只能在该方法中使用。GetHashCode我最终采用的解决方案是在ObservableCollection编辑方法中使用的任何属性之前从其中删除每个项目GetHashCode,然后再次重新添加它。虽然到目前为止,这在许多视图中都运行良好,但我遇到了进一步的问题,因为我的 UI 项目是使用自定义动画的Panel。当我重新添加一个项目时(即使将其插入到集合中的原始索引中),它会再次启动条目动画。
我已经添加了一些基类方法,例如AddWithoutAnimation, RemoveWithoutAnimation,这有助于解决其中一些问题,但它不会影响任何Storyboard动画,重新添加后仍然会触发动画。最后,我们来回答这个问题:
首先,我想明确声明,我没有Dictionary在代码中使用任何对象...Dictionary抛出 的对象必须Exception是ObservableCollection<T>. 我上一个问题中似乎大多数人都忽略了这一点。因此,我不能选择干脆不使用Dictionary……如果可以的话。 …
wpf ×9
c# ×6
mvvm ×2
xaml ×2
.net ×1
bitmap ×1
gethashcode ×1
overriding ×1
performance ×1
rate ×1
tab-ordering ×1
transfer ×1
windows ×1
windows-8.1 ×1