當前位置:首頁 » 文件管理 » wpf上傳控制項

wpf上傳控制項

發布時間: 2022-08-10 12:11:04

❶ 如何在WPF中嵌入Winform控制項

1. 新建一個基於.Net Framework 3.5 的WPF 應用程序項目:WPFWMP。
2. 在工程中新建Windows Forms Control Library 項目:WMPControlLibrary。
創建WMP 控制項
下面要在WMPControlLibrary 中創建Windows Media Player 控制項,在項目中加入Windows Media Player COM。
在左側工具欄中若沒有Windows Media Player 控制項的話,可以右鍵General 選擇Choose Items,在COM 組件列表中勾選Windows Media Player 選項。
將Windows Media Player 控制項拖入設計窗口,並將Dock 設置為Fill 填充控制項。
F6 編譯項目後會生成以下三個DLL 文件,這就是我們稍後將要在WPF 中用到的WMP 控制項庫。
嵌入WMP 控制項
回到WPF 項目在前篇文章的基礎上,保留其中「Open File」 按鍵和Button 樣式。將上面三個DLL 文件及System.Windows.Forms、WindowsFormsIntegration 加入項目。
在XAML 中加入AxWMPLib 命名空間,並將上篇MediaElement 替換為AxWindowsMediaPlayer 控制項,注意此處是將WinForm 控制項嵌入WPF 程序,所以要將AxWindowsMediaPlayer 控制項放到<WindowsFormsHost>標簽中。
<Window x:Class="WPFWMP.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mediaControl="clr-namespace:AxWMPLib;assembly=AxInterop.WMPLib"
Title="WPF Media Player" Height="450" Width="520" Background="#FF554D4D">
<Window.Resources>
<Style x:Key="btnStyle" TargetType="Button">
… …
</Style>
</Window.Resources>
<StackPanel HorizontalAlignment="Center" Margin="10">
<Border BorderThickness="3" Background="Black">
… …
<WindowsFormsHost Height="340" Width="450">
<mediaControl:AxWindowsMediaPlayer x:Name="wpfMediaPlayer"/>
</WindowsFormsHost>
</Border>
<Button Content="Open File" Click="openFile_Click" Margin="10"
Width="80" Style="{StaticResource btnStyle}"/>
</StackPanel>
</Window>

通過Windows API Code Pack 為「Open File」 按鍵添加點擊事件,默認打開Sample Video 文件夾,選擇視頻文件後自動播放。
private void openFile_Click(object sender, RoutedEventArgs e)
{
ShellContainer selectedFolder = null;
selectedFolder = KnownFolders.SampleVideos as ShellContainer;
CommonOpenFileDialog cfd = new CommonOpenFileDialog();
cfd. = selectedFolder;
cfd.EnsureReadOnly = true;
cfd.Filters.Add(new CommonFileDialogFilter("WMV Files", "*.wmv"));
cfd.Filters.Add(new CommonFileDialogFilter("AVI Files", "*.avi"));
cfd.Filters.Add(new CommonFileDialogFilter("MP3 Files", "*.mp3"));

if (cfd.ShowDialog() == CommonFileDialogResult.OK)
{
wpfMediaPlayer.URL = cfd.FileName;
}
}

❷ 如何在WPF中調用Winform控制項

功能實現主要分三步:
1、添加兩個引用:WindowsFormsIntegration.dll(負責整合WPF和Windows)、System.Windows.Forms.
2、在 XAML文件中添加兩個引用(粗體部分):

<Window x:Class="CrossBowDemo.MainWindow"
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Hosting Windows Forms Control In WPF"
Height="300"
Width="650"
ResizeMode="NoResize"
Loaded="WindowLoadedHandler"
>

< /Window>

3、在XAML編碼區實現你想添加的控制項:

原文添加的是DataGridView控<wfi:WindowsFormsHost>
<wf:DataGridView x:Name="Dg" Dock="Fill" SelectionMode="FullRowSelect">
</wf:DataGridView>
</wfi:WindowsFormsHost>件:

❸ wpf添加新控制項原本的控制項消失

動態添加控制項——在後台實例化需要添加的控制項,然後將這個控制項放進容器里
例如Grid.children.add(控制項)
原本的控制項消失——有兩種做法 1.將控制項的visibility 設為collapse 2.將容器里這個控制項移除
例如Grid.children.remove(控制項)
以上這兩個邏輯操作放在一個事件里完成就行啦。

❹ WPF 動態添加控制項與設置控制項模版

首先呢,DataTemplate作為Resource的一種呢,是用key來被識別的,不用設置name的。
其次我來說一下關於你兩個問題的一些看法。
問題一——你這種問法相當於如何在後台對一個控制項的Content添加一個控制項。一般解決的方法為
後台先創建好listbox,然後賦值 expander1.Content=listbox;
問題二:如何後台指定控制項模板。你後台創建一個listbox。 那就可以像一般屬性一樣賦給它的控制項模板呀。
listbox.ItemTemplate = Resources["lbItemTemp"] as DataTemplate;

熱點內容
cad解壓錯誤 發布:2024-03-29 15:01:45 瀏覽:78
存儲指令集 發布:2024-03-29 14:39:27 瀏覽:649
資料庫表刪除數據 發布:2024-03-29 14:39:26 瀏覽:367
出c語言整除 發布:2024-03-29 14:28:22 瀏覽:572
芬尼壓縮機 發布:2024-03-29 14:24:11 瀏覽:464
電腦數據實時上傳本地伺服器軟體 發布:2024-03-29 14:07:57 瀏覽:920
尋秦記源碼 發布:2024-03-29 13:56:17 瀏覽:496
linux的備份命令 發布:2024-03-29 13:41:22 瀏覽:383
csgo建議什麼配置 發布:2024-03-29 13:31:44 瀏覽:980
電腦ftp服務如何禁用 發布:2024-03-29 13:24:48 瀏覽:332