none
OpenFileDialog RRS feed

Ответы

  • Silverlight?

    XAML:

    <UserControl x:Class="SilverlightApplication9.MainPage"
      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/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      d:DesignHeight="300" d:DesignWidth="400">
    
      <Grid x:Name="LayoutRoot" Margin="3" >
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="0"
           VerticalAlignment="Center"
           HorizontalAlignment="Center"
           x:Name="Message">
       Choose An Image
        </TextBlock>
        <Button Grid.Row="0" Grid.Column="1"
          Content="Browse..." Click="BrowseClick" />
        <Image Margin="3" x:Name="ImageHolder"
         Grid.ColumnSpan="2" Grid.Row="1"
         Grid.Column="0" Stretch="UniformToFill" />
      </Grid>
    </UserControl>
    
    

    Код:

        private void BrowseClick(object sender, RoutedEventArgs e)
        {
          OpenFileDialog ofd = new OpenFileDialog();
          ofd.Multiselect = false;
          bool? result = ofd.ShowDialog();
          if (!result.HasValue || result.Value == false)
            return;
    
          BitmapImage imageSource = new BitmapImage();
          try
          {
            imageSource.SetSource(ofd.File.OpenRead());
            ImageHolder.Source = imageSource;
            Message.Text = "Showing " + ofd.File.Name;
          }
          catch (Exception)
          {
            Message.Text = "Error Loading File";
          }
        }
    

    (Источник)


    Для связи [mail]
    • Помечено в качестве ответа saiman_OK 1 апреля 2011 г. 19:28
    1 апреля 2011 г. 13:41
    Модератор