小编Bar*_*ead的帖子

查找在Windows上打开特定文件类型的默认应用程序

我正在使用C#开发一个面向.NET Framework 2.0的应用程序,我需要能够找到用于打开特定文件类型的默认应用程序.

我知道,例如,如果您只想使用该应用程序打开文件,您可以使用以下内容:

System.Diagnostics.Process.Start( "C:\...\...\myfile.html" );
Run Code Online (Sandbox Code Playgroud)

在默认浏览器中打开HTML文档,或

System.Diagnostics.Process.Start( "C:\...\...\myfile.txt" );
Run Code Online (Sandbox Code Playgroud)

在默认文本编辑器中打开文本文件.

但是,我希望能够在默认文本编辑器中打开不一定具有.txt扩展名的文件(例如),因此我需要能够找到打开的默认应用程序. txt文件,这将允许我直接调用它.

我猜测有一些Win32 API,我需要P/Invoke才能做到这一点,但是对谷歌和MSDN的快速浏览并没有发现任何有趣的东西; 我确实找到了大量完全不相关的页面,但没有像我在寻找的那样.

.net c# windows file-type

52
推荐指数
4
解决办法
4万
查看次数

WPF控件不在WinForms应用程序中的ElementHost中显示

我有一个WPF控件的问题,我试图在WinForms应用程序中的ElementHost中托管.该控件是一个无形的自定义控件,我最初是在一个单独的测试项目中开发的,它是一个WPF应用程序.在那里它显然工作正常,但在我的WinForms应用程序中,我得到的是一个空白的灰色框,其中显示ElementHost.

这是我用于创建,填充和添加ElementHost到父Control的C#代码:

// This is my WPF control
m_TabHostPanel  = new TabHostPanel();
m_ElementHost  = new ElementHost
                 {
                     Child = m_TabHostPanel,
                     Dock = DockStyle.Top,
                     Height = 34
                 };
this.Controls.Add( m_ElementHost );
Run Code Online (Sandbox Code Playgroud)

父控件包含在运行时根据需要添加和删除的其他WinForms控件.这些都是单独托管,其Dock设置为DockStyle.Fill.因此,每次添加一个时,我都会将ElementHost发送到Z-order的后面,以确保它正确呈现:

m_ElementHost.SendToBack();
Run Code Online (Sandbox Code Playgroud)

因此,我知道我没有遇到空域问题,或类似的问题.

我想知道的一件事是这样的:在原始项目中,我所有无外观控件的样式被合并到App.xaml中的应用程序的资源字典中,如下所示:

<Application x:Class="WpfTestApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Application/UserInterface/DataTemplates/TabModelDataTemplate.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/HoverablePressableButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/MiniControlButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabCloseButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabScrollLeftButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabScrollRightButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabListDropDownButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabHostComboBoxStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabHostPanelStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)

我已将App.xaml迁移到我的WinForms项目,但构建操作设置为Page.如果我将它设置为ApplicationDefinition,我得到一个错误,说应用程序有多个入口点,这是有道理的,但我想知道是否正在拾取样式等.如果不是这可能解释为什么我得到一个空白的灰色矩形,我的控制应该是因为没有这些,没有什么可以定义它的外观.所以也许问题是,我如何将这些样式放入我的WinForms应用程序中,以便我的WPF控件可以看到它们?

我可能还应该提到这是在.NET Fx 3.5上运行的.

无论如何,现在我很困惑,所以任何帮助都会感激不尽.

非常感谢!

巴特

.net wpf xaml elementhost winforms

10
推荐指数
1
解决办法
9032
查看次数

如何在WPF按钮内绘制尺寸为控件的形状或线条,而不会使按钮永远展开?

我有一个快速的谷歌,并快速浏览StackOverflow,但找不到其他任何人遇到这个问题.

我想创建一个带有小X的关闭按钮.当你将鼠标悬停在包含它的项目上时,关闭按钮会执行淡入和淡出等操作,当鼠标悬停时更改颜色,以及所有常用的WPF可爱.最重要的是,它看起来似乎不应该那么困难,但是我已经遇到了在我进入这个阶段之前的一个最奇怪的问题.

这是按钮的XAML样式:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="TabCloseButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Content">
            <Setter.Value>
                <Grid>
                    <Line Stroke="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"
                            X1="0"
                            Y1="0"
                            X2="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=ActualWidth, Mode=OneWay}"
                            Y2="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=ActualHeight, Mode=OneWay}"/>
                    <Line Stroke="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}"
                            X1="0"
                            Y1="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=ActualHeight, Mode=OneWay}"
                            X2="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=ActualWidth, Mode=OneWay}"
                            Y2="0"/>
                </Grid>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

我创建我的按钮,就像测试一样,如下所示:

<Window x:Class="WpfTestApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="124" Width="569">
    <Grid Background="#2b3c59">
        <StackPanel Orientation="Horizontal">

            <!-- Other controls removed for clarity --> …
Run Code Online (Sandbox Code Playgroud)

size wpf xaml button

7
推荐指数
1
解决办法
2万
查看次数

在节点上安装Karma时出错 - 在OSX上检索当前目录时出错

我今天一直在努力解决这个问题,并且无法弄清楚问题是什么 - 不幸的是谷歌没有太多帮助.

我正在尝试遵循AngularJS教程,但无法安装Karma.每次我尝试时都会收到错误消息"检索当前目录时出错:getcwd:无法访问父目录:权限被拒绝".

这是bash中输出的副本:

Barts-MacBook-Pro:~ bart$ sudo npm install -g karma
Password:
npm http GET https://registry.npmjs.org/karma
npm http GET https://registry.npmjs.org/karma
npm http 200 https://registry.npmjs.org/karma
npm http GET https://registry.npmjs.org/karma/-/karma-0.8.5.tgz
npm http 200 https://registry.npmjs.org/karma/-/karma-0.8.5.tgz
npm http GET https://registry.npmjs.org/chokidar
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/socket.io
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/xmlbuilder/0.4.2
npm http GET https://registry.npmjs.org/optimist/0.3.5
npm http GET https://registry.npmjs.org/colors/0.6.0-1
npm http GET https://registry.npmjs.org/LiveScript/1.0.1
npm http GET https://registry.npmjs.org/dateformat/1.0.2-1.2.3
npm http GET https://registry.npmjs.org/mime
npm http GET …
Run Code Online (Sandbox Code Playgroud)

node.js npm angularjs karma-runner

3
推荐指数
1
解决办法
3406
查看次数

标签 统计

.net ×2

wpf ×2

xaml ×2

angularjs ×1

button ×1

c# ×1

elementhost ×1

file-type ×1

karma-runner ×1

node.js ×1

npm ×1

size ×1

windows ×1

winforms ×1