我正在尝试下面的代码,它有两个部分,一个是通过棱镜导航.当允许导航时,我以异步方式开始深度加载,但每次都使用新的上下文.在以后的代码中,我想要取消未完成此加载的挂起导航,但下面的代码甚至不起作用,因此取消是稍后的事情;-)
导航逻辑:这里没问题
public void OnNavigatedTo(NavigationContext navigationContext)
{
int relatieId = (int)navigationContext.Parameters["RelatieId"];
if (_relatie != null && _relatie.RelatieId == relatieId) return;
loadRelatieAsync(relatieId);
}
public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
{
bool navigationAllowed = true;
continuationCallback(navigationAllowed);
}
Run Code Online (Sandbox Code Playgroud)
深度加载逻辑:
private async Task loadRelatieAsync(int relatieId)
{
try
{
await Task.Run(async () =>
{
_unitOfWork = _UnitOfWorkFactory.createUnitOfWorkAsync();
IEnumerable<Relatie> relaties = await getRelatieAsync(_unitOfWork, relatieId).ConfigureAwait(true);
_relatieTypeTypes = await getRelatieTypeTypesAsync(_unitOfWork, relatieId).ConfigureAwait(true);
_relatie = relaties.FirstOrDefault();
_unitOfWork.Dispose();
}).ConfigureAwait(true);
processRelatie(_relatie);
processRelatieTypes(_relatie, _relatieTypeTypes);
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
throw;
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个 WPF PRISM 应用程序,其主窗口基于 ribbinwindow。当我右键单击图标托盘中的图标时,退出菜单被禁用。有人可以告诉我如何启用它并正确处理关闭事件。
我显示了主窗口的整个代码,但让我头疼的是通知图标的上下文菜单。我通过尝试用谷歌搜索解决此问题,找到了placementTarget commandtarget 绑定,但这似乎不起作用。
功能区按钮也以与上下文菜单相同的方式绑定,确实按预期工作。
在这种情况下,我更愿意保留命令绑定而不处理事件,因为我正在使用 MVVM。可以通过简单地调用一个事件并在该事件中调用 close 来处理关闭,而不会出现关注点分离问题,但我也将使用其他命令。所以请不要举办任何活动。
<ribbon:RibbonWindow x:Class="_2Focus.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ribbon="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"
xmlns:prism="http://www.codeplex.com/prism"
xmlns:tb="http://www.hardcodet.net/taskbar"
Title="2Focus" Icon="/2Focus;component/favicon.ico"
x:Name="Mainwindow"
Height="500" Width="900">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition x:Name="RibbonRow" Height="Auto"/>
<RowDefinition x:Name="ClientRow" Height="*"/>
</Grid.RowDefinitions>
<tb:TaskbarIcon IconSource="/2Focus;component/favicon.ico" ToolTipText="2 Focus" >
<tb:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Exit" Command="ApplicationCommands.Close"
CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}">
<MenuItem.Icon>
<Image Source="Images/exit.png" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Second Menu Item" />
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>
<ribbon:Ribbon x:Name="Ribbon" prism:RegionManager.RegionName="RibbonRegion" SelectionChanged="Ribbon_SelectionChanged" >
<ribbon:Ribbon.QuickAccessToolBar>
<ribbon:RibbonQuickAccessToolBar Name="ribbonQuickAccessToolBar" AllowDrop="True" />
</ribbon:Ribbon.QuickAccessToolBar>
<ribbon:Ribbon.ApplicationMenu>
<ribbon:RibbonApplicationMenu SmallImageSource="/2Focus;component/favicon.ico"> …Run Code Online (Sandbox Code Playgroud) 我使用以下代码通过系统上安装的任意应用程序打开任意文件:
if (File.Exists(_document.DocumentFullPath))
{
Process.Start(_document.DocumentFullPath);
}
else MessageBox.Show(string.Format("Document {0} does not exist!", _document.DocumentFullPath));
Run Code Online (Sandbox Code Playgroud)
当我执行此代码时,我看到 file.Exists 返回 true,因此该文件确实存在。但随后会打开相应的应用程序,例如图像查看器或 pdf 查看器,具体取决于我尝试打开的文件类型(jpg 或 pdf),但它在该应用程序中显示错误,无法找到该文件。不会引发任何异常。这种情况并不总是发生,而是仅发生在某些文件上。如果我尝试通过在资源管理器中复制粘贴 DocumentFullPath 的内容来手动打开这些文件,则该文件会在适用的应用程序中正确打开。
呃,我不明白出了什么问题。无效的文件名示例:
C:\Users\stuyckp\Documents\Visual Studio 2010\Projects\WPF\FrakoKlantOpvolgingWPF\FrakoKlantOpvolgingWPF\bin\Debug\ProjectDocumenten\11339_Wigbers\6197_koelkast \big-money.jpg
Run Code Online (Sandbox Code Playgroud)
我在 Windows 10 上运行。
A看到了以下代码的问题:
union
{
float dollars;
int yens;
}price;
Run Code Online (Sandbox Code Playgroud)
price是一个类型没有名称的变量.什么是这种无名类型有用?Lambda表达式?这在C和C++中都有效吗?