Exemplo n.º 1
0
 /// <summary>
 /// Sets the dialog result associated with the button.
 /// </summary>
 /// <param name="button">The button.</param>
 /// <param name="value">The associated dialog result.</param>
 public static void SetDialogResult([NotNull] System.Windows.Controls.Button button, bool?value)
 {
     button.SetValue(DialogResultProperty, value);
 }
Exemplo n.º 2
0
        // Load up ink from an ISF file that the user selects from the OpenFileDialog.
        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            SigBank.Children.Clear();
            if (SigBank.Visibility == Visibility.Collapsed)
            {
                LoadButton.ButtonText = "Close";

                // Read all signatures from ..//sigBank
                string   sigBankImagePath    = AppDomain.CurrentDomain.BaseDirectory + "\\sigBank\\img";
                string[] sigImagePaths       = Directory.GetFiles(sigBankImagePath);
                string[] recentSigImagePaths = new string[4];

                // Get array with last 4 entries of "sigImagePaths", associate these with the buttons somehow (TODO)
                int count = 0;
                while (count < sigImagePaths.Length && count < 4)
                {
                    recentSigImagePaths[count] = sigImagePaths[(sigImagePaths.Length - 1) - count];
                    count++;
                }

                // Iterate over thumbnails files and convert to Image.
                // Then add Image to respective sigBank column & row.
                // NOTE:: if you have time you can dynamically allocate rows and columns for better UI.
                int row = 0;
                for (int i = 0; i < 4 && recentSigImagePaths[i] != null; i++)
                {
                    if (i == 2)
                    {
                        row++;
                    }                      // go to next row for 3rd and 4th thumbnails

                    // create new image from file path
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
                    BitmapImage src = new BitmapImage();
                    src.BeginInit();
                    src.UriSource   = new Uri(recentSigImagePaths[i], UriKind.Relative);
                    src.CacheOption = BitmapCacheOption.OnLoad;
                    src.EndInit();
                    img.Source  = src;
                    img.Height  = Height / 3; //set image size (consider programatically creating margins)
                    img.Width   = Width / 3;
                    img.Stretch = Stretch.Uniform;

                    //replace special characters in path with octal rep. for btn name property
                    string name = recentSigImagePaths[i].Replace(":", "3A").Replace("\\", "5C").Replace(".jpg", "");

                    //create button to wrap image and bind Click event
                    System.Windows.Controls.Button btn = new System.Windows.Controls.Button();
                    btn.Name    = name;
                    btn.Click  += ThumbnailButton_Click;
                    btn.Content = img;
                    btn.SetValue(System.Windows.Controls.Grid.ColumnProperty, i % 2); //assign row & column and row propeties
                    btn.SetValue(System.Windows.Controls.Grid.RowProperty, row);
                    btn.MaxHeight   = img.Height;
                    btn.MaxWidth    = img.Width;
                    btn.Background  = Brushes.Transparent;
                    btn.BorderBrush = Brushes.Transparent;

                    SigBank.Children.Add(btn);
                }

                SigBank.Visibility = Visibility.Visible;
                SigBank.IsEnabled  = true;
            }
            else
            {
                LoadButton.ButtonText = "Load";
                SigBank.Visibility    = Visibility.Collapsed;
                SigBank.IsEnabled     = false;
            }
        }