example WPF fileDialog

索引サイトへ
ファイル選択

XAML




<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Wpf-AX-2211-VB" Height="500" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="409*" />
<RowDefinition Height="52*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="559*" />
<ColumnDefinition Width="35*" />
<ColumnDefinition Width="74*" />
<ColumnDefinition Width="110*" />
</Grid.ColumnDefinitions>

<Viewbox x:Name="Viewbox_AX2211" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006" xmlns:c="http://schemas.openxmlformats.org/markup-compatibility/2006" c:Ignorable="d" Margin="5">
<Viewport3D x:Name="Viewport3D_AX2211" Margin="5" Width="400" Height="100">
<Viewport3D.Resources>
<ResourceDictionary>
<MaterialGroup x:Key="Material_AX2211_mat1" >
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<VisualBrush>
<VisualBrush.Visual>
<MediaElement Source="{Binding ElementName=LabelWMV,Path=Content}" />
</VisualBrush.Visual>
</VisualBrush>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
<Transform3DGroup x:Key="Transform_Character_AX2211_Character_0" >
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
<ScaleTransform3D ScaleX="1" ScaleY="1" ScaleZ="1"/>
<RotateTransform3D CenterX="0" CenterY="0" CenterZ="0">
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="0" Axis="0 1 0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
</Transform3DGroup>

<Transform3DGroup x:Key="Transform_Model_AX2211_obj1" >
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
<ScaleTransform3D CenterX="0.000000" CenterY="0.000000" CenterZ="0.000000" ScaleX="1" ScaleY="1" ScaleZ="1"/>

<RotateTransform3D CenterX="0.000000" CenterY="0.000000" CenterZ="0.000000">
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="{Binding ElementName=SliderX,Path=Value}" Axis="1 0 0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D CenterX="0.000000" CenterY="0.000000" CenterZ="0.000000">
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="{Binding ElementName=SliderY,Path=Value}" Axis="0 1 0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D CenterX="0.000000" CenterY="0.000000" CenterZ="0.000000">
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="{Binding ElementName=SliderZ,Path=Value}" Axis="0 0 1"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
<TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"/>
</Transform3DGroup>

<MeshGeometry3D x:Key="Geometry_AX2211_obj1_0"
TriangleIndices="2,1,0 3,2,0 5,4,1 2,5,1 7,6,4 5,7,4 3,0,6 7,3,6 1,4,6 0,1,6 5,2,3 7,5,3 "
Positions="-160.750000,100.000000,10.200000 160.750000,100.000000,10.200000 160.750000,-100.000000,10.200000 -160.750000,-100.000000,10.200000 160.750000,100.000000,-10.200000 160.750000,-100.000000,-10.200000 -160.750000,100.000000,-10.200000 -160.750000,-100.000000,-10.200000 "
TextureCoordinates="0,0 1,0 1,1 0,1"
Normals="0,0,1 0,0,1 0,0,1 0,0,1"
/>
</ResourceDictionary>
</Viewport3D.Resources>

<Viewport3D.Camera>
<PerspectiveCamera x:Name="Camera_AX2211" Position="-244.763901,513.030212,1388.125000" LookDirection="0.163176,-0.342020,-0.925416" UpDirection="0.000000,1.000000,0.000000" FieldOfView="{Binding ElementName=SliderFieldOfView,Path=Value}" NearPlaneDistance="1" FarPlaneDistance="10000" />
</Viewport3D.Camera>

<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<AmbientLight Color="#646464" />
<DirectionalLight x:Name="Light_AX2211" Color="#FFFFFF" Direction="0.163176,-0.342020,-0.925416" />
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="Character_AX2211_Character_0" Transform="{StaticResource Transform_Character_AX2211_Character_0}">
<ModelVisual3D.Content>
<Model3DGroup>
<Model3DGroup x:Name="Model_AX2211_obj1" Transform="{StaticResource Transform_Model_AX2211_obj1}">
<GeometryModel3D x:Name="Geometry_Model_AX2211_obj1_0" Geometry="{StaticResource Geometry_AX2211_obj1_0}" Material="{StaticResource Material_AX2211_mat1}"/>
</Model3DGroup>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>

<Viewbox.Resources>
<Storyboard Duration="Forever" FillBehavior="HoldEnd" BeginTime="0:0:0" x:Key="Animation_AX2211_Animation_0">
</Storyboard>
</Viewbox.Resources>

<Viewbox.Triggers>
<EventTrigger RoutedEvent="Viewport3D.Loaded">
<EventTrigger.Actions>
<BeginStoryboard Storyboard="{StaticResource Animation_AX2211_Animation_0}" />
</EventTrigger.Actions>
</EventTrigger>
</Viewbox.Triggers>
</Viewbox>

<Slider Height="24" HorizontalAlignment="Left" Margin="29,137,0,0" Name="SliderX" VerticalAlignment="Top" Width="115" Grid.Column="2" Maximum="360" Grid.ColumnSpan="2">
<Slider.RenderTransform>
<RotateTransform CenterX="45" CenterY="45" Angle="0"/>
</Slider.RenderTransform>
</Slider>
<Slider Height="24" HorizontalAlignment="Left" Margin="14,15,0,0" Name="SliderZ" VerticalAlignment="Top" Width="105" Maximum="360" Grid.Column="2" Grid.ColumnSpan="2">
<Slider.RenderTransform>
<RotateTransform Angle="140" CenterX="45" CenterY="45" />
</Slider.RenderTransform>
</Slider>
<Slider Height="24" HorizontalAlignment="Left" Margin="48,41,0,0" Name="SliderY" VerticalAlignment="Top" Width="69" Grid.Column="3" Maximum="360">
<Slider.RenderTransform>
<RotateTransform Angle="270" CenterX="45" CenterY="45" />
</Slider.RenderTransform>
</Slider>
<Label Content="{Binding ElementName=SliderY,Path=Value}" Height="25" HorizontalAlignment="Left" Margin="6,12,0,0" Name="LabelY" VerticalAlignment="Top" Width="84" Grid.Column="2" Background="#FFC9F5C9" Grid.ColumnSpan="2" />
<Label Content="{Binding ElementName=SliderZ,Path=Value}" Height="25" HorizontalAlignment="Left" Margin="6,195,0,0" Name="LabelZ" VerticalAlignment="Top" Width="84" Grid.Column="2" Background="#FFC3C3F5" Grid.ColumnSpan="2" />
<Label Content="{Binding ElementName=SliderX,Path=Value}" Height="25" HorizontalAlignment="Left" Margin="22,195,0,0" Name="LabelX" VerticalAlignment="Top" Width="84" Grid.Column="3" Background="#FFF88383" />
<Label Background="#FFC3C3F5" HorizontalAlignment="Stretch" Margin="10" Name="LabelWMV" VerticalAlignment="Stretch" Grid.Row="1" Content="FileID" />
<Button Content="Select WMV" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Stretch" Margin="10" Name="ButtonShowDialig" VerticalAlignment="Stretch" Grid.ColumnSpan="2" />
<Slider Grid.Column="1" HorizontalAlignment="Stretch" Margin="5" Name="SliderFieldOfView" VerticalAlignment="Stretch" Orientation="Vertical" Minimum="10" Maximum="90" Value="28" />
</Grid>
</Window>

VB2010


Class MainWindow
Private Sub ButtonShowDialig_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonShowDialig.Click
Dim result As Boolean
Dim openFileDialog = New Microsoft.Win32.OpenFileDialog()

openFileDialog.Filter = "WMVファイル|*.wmv|すべてのファイル|*.*"
openFileDialog.InitialDirectory = "c:"
openFileDialog.CheckFileExists = True
openFileDialog.Multiselect = True
openFileDialog.ShowReadOnly = False
openFileDialog.Title = "表示ファイルの選択"
result = openFileDialog.ShowDialog()

Me.LabelWMV.Content = openFileDialog.FileName.ToString
End Sub
End Class

C#2010
XAML x:class が異なる



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
///


/// MainWindow.xaml の相互作用ロジック
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
bool result = false;
dynamic openFileDialog = new Microsoft.Win32.OpenFileDialog();

openFileDialog.Filter = "WMVファイル|*.wmv|すべてのファイル|*.*";
openFileDialog.InitialDirectory = "c:\\wmv";
openFileDialog.CheckFileExists = true;
openFileDialog.Multiselect = true;
openFileDialog.ShowReadOnly = false;
openFileDialog.Title = "表示ファイルの選択";
result = openFileDialog.ShowDialog();

this.LabelWMV.Content = openFileDialog.FileName;
}
}
}



AX