@@ -340,36 +340,46 @@ public virtual async Task InitAsync(PluginInitContext context)
340
340
this . context = context ;
341
341
await InitSettingAsync ( ) ;
342
342
}
343
- private static readonly Thickness settingControlMargin = new ( 10 , 4 , 10 , 4 ) ;
344
- private static readonly Thickness settingPanelMargin = new ( 15 , 20 , 15 , 20 ) ;
345
- private static readonly Thickness settingTextBlockMargin = new ( 10 , 4 , 10 , 4 ) ;
343
+ private static readonly Thickness settingControlMargin = new ( 0 , 6 , 0 , 6 ) ;
344
+ private static readonly Thickness settingPanelMargin = new ( 70 , 18 , 18 , 18 ) ;
345
+ private static readonly Thickness settingTextBlockMargin = new ( 0 , 6 , 0 , 6 ) ;
346
+ private static readonly Thickness settingLabelMargin = new ( 0 , 0 , 18 , 0 ) ;
346
347
private JsonRpcConfigurationModel _settingsTemplate ;
347
348
348
349
public Control CreateSettingPanel ( )
349
350
{
350
351
if ( Settings == null )
351
352
return new ( ) ;
352
353
var settingWindow = new UserControl ( ) ;
353
- var mainPanel = new StackPanel
354
+ var mainPanel = new Grid
354
355
{
355
- Margin = settingPanelMargin , Orientation = Orientation . Vertical
356
+ Margin = settingPanelMargin
356
357
} ;
358
+ ColumnDefinition gridCol1 = new ColumnDefinition ( ) { Width = GridLength . Auto } ;
359
+ ColumnDefinition gridCol2 = new ColumnDefinition ( ) ;
360
+ gridCol2 . Width = new GridLength ( 75 , GridUnitType . Star ) ;
361
+ mainPanel . ColumnDefinitions . Add ( gridCol1 ) ;
362
+ mainPanel . ColumnDefinitions . Add ( gridCol2 ) ;
363
+
357
364
settingWindow . Content = mainPanel ;
358
-
365
+ int rowCount = 0 ;
359
366
foreach ( var ( type , attribute ) in _settingsTemplate . Body )
360
367
{
361
- var panel = new StackPanel
362
- {
363
- Orientation = Orientation . Horizontal , Margin = settingControlMargin
364
- } ;
368
+ //var panel = new StackPanel
369
+ //{
370
+ //Orientation = Orientation.Horizontal, Margin = settingControlMargin
371
+ //};
372
+ RowDefinition gridRow = new RowDefinition ( ) ;
373
+ mainPanel . RowDefinitions . Add ( gridRow ) ;
365
374
var name = new TextBlock ( )
366
375
{
367
376
Text = attribute . Label ,
368
- Width = 120 ,
369
377
VerticalAlignment = VerticalAlignment . Center ,
370
- Margin = settingControlMargin ,
378
+ Margin = settingLabelMargin ,
371
379
TextWrapping = TextWrapping . WrapWithOverflow
372
380
} ;
381
+ Grid . SetColumn ( name , 0 ) ;
382
+ Grid . SetRow ( name , rowCount ) ;
373
383
374
384
FrameworkElement contentControl ;
375
385
@@ -381,10 +391,15 @@ public Control CreateSettingPanel()
381
391
{
382
392
Text = attribute . Description . Replace ( "\\ r\\ n" , "\r \n " ) ,
383
393
Margin = settingTextBlockMargin ,
384
- MaxWidth = 500 ,
394
+ VerticalAlignment = VerticalAlignment . Center ,
395
+ HorizontalAlignment = HorizontalAlignment . Left ,
396
+ TextAlignment = TextAlignment . Left ,
385
397
TextWrapping = TextWrapping . WrapWithOverflow
386
398
} ;
387
- break ;
399
+ Grid . SetColumn ( contentControl , 0 ) ;
400
+ Grid . SetColumnSpan ( contentControl , 2 ) ;
401
+ Grid . SetRow ( contentControl , rowCount ) ;
402
+ break ;
388
403
}
389
404
case "input" :
390
405
{
@@ -393,14 +408,17 @@ public Control CreateSettingPanel()
393
408
Width = 300 ,
394
409
Text = Settings [ attribute . Name ] as string ?? string . Empty ,
395
410
Margin = settingControlMargin ,
411
+ HorizontalAlignment = HorizontalAlignment . Left ,
396
412
ToolTip = attribute . Description
397
413
} ;
398
414
textBox . TextChanged += ( _ , _ ) =>
399
415
{
400
416
Settings [ attribute . Name ] = textBox . Text ;
401
417
} ;
402
418
contentControl = textBox ;
403
- break ;
419
+ Grid . SetColumn ( contentControl , 1 ) ;
420
+ Grid . SetRow ( contentControl , rowCount ) ;
421
+ break ;
404
422
}
405
423
case "textarea" :
406
424
{
@@ -411,6 +429,7 @@ public Control CreateSettingPanel()
411
429
Margin = settingControlMargin ,
412
430
TextWrapping = TextWrapping . WrapWithOverflow ,
413
431
AcceptsReturn = true ,
432
+ HorizontalAlignment = HorizontalAlignment . Left ,
414
433
Text = Settings [ attribute . Name ] as string ?? string . Empty ,
415
434
ToolTip = attribute . Description
416
435
} ;
@@ -419,7 +438,9 @@ public Control CreateSettingPanel()
419
438
Settings [ attribute . Name ] = ( ( TextBox ) sender ) . Text ;
420
439
} ;
421
440
contentControl = textBox ;
422
- break ;
441
+ Grid . SetColumn ( contentControl , 1 ) ;
442
+ Grid . SetRow ( contentControl , rowCount ) ;
443
+ break ;
423
444
}
424
445
case "passwordBox" :
425
446
{
@@ -429,14 +450,17 @@ public Control CreateSettingPanel()
429
450
Margin = settingControlMargin ,
430
451
Password = Settings [ attribute . Name ] as string ?? string . Empty ,
431
452
PasswordChar = attribute . passwordChar == default ? '*' : attribute . passwordChar ,
453
+ HorizontalAlignment = HorizontalAlignment . Left ,
432
454
ToolTip = attribute . Description
433
455
} ;
434
456
passwordBox . PasswordChanged += ( sender , _ ) =>
435
457
{
436
458
Settings [ attribute . Name ] = ( ( PasswordBox ) sender ) . Password ;
437
459
} ;
438
460
contentControl = passwordBox ;
439
- break ;
461
+ Grid . SetColumn ( contentControl , 1 ) ;
462
+ Grid . SetRow ( contentControl , rowCount ) ;
463
+ break ;
440
464
}
441
465
case "dropdown" :
442
466
{
@@ -445,36 +469,45 @@ public Control CreateSettingPanel()
445
469
ItemsSource = attribute . Options ,
446
470
SelectedItem = Settings [ attribute . Name ] ,
447
471
Margin = settingControlMargin ,
472
+ HorizontalAlignment = HorizontalAlignment . Left ,
448
473
ToolTip = attribute . Description
449
474
} ;
450
475
comboBox . SelectionChanged += ( sender , _ ) =>
451
476
{
452
477
Settings [ attribute . Name ] = ( string ) ( ( ComboBox ) sender ) . SelectedItem ;
453
478
} ;
454
479
contentControl = comboBox ;
455
- break ;
480
+ Grid . SetColumn ( contentControl , 1 ) ;
481
+ Grid . SetRow ( contentControl , rowCount ) ;
482
+ break ;
456
483
}
457
484
case "checkbox" :
458
485
var checkBox = new CheckBox
459
486
{
460
487
IsChecked = Settings [ attribute . Name ] is bool isChecked ? isChecked : bool . Parse ( attribute . DefaultValue ) ,
461
488
Margin = settingControlMargin ,
489
+ HorizontalAlignment = HorizontalAlignment . Left ,
462
490
ToolTip = attribute . Description
463
491
} ;
464
492
checkBox . Click += ( sender , _ ) =>
465
493
{
466
494
Settings [ attribute . Name ] = ( ( CheckBox ) sender ) . IsChecked ;
467
495
} ;
468
496
contentControl = checkBox ;
497
+ Grid . SetColumn ( contentControl , 1 ) ;
498
+ Grid . SetRow ( contentControl , rowCount ) ;
469
499
break ;
470
500
default :
471
501
continue ;
472
502
}
473
503
if ( type != "textBlock" )
474
504
_settingControls [ attribute . Name ] = contentControl ;
475
- panel . Children . Add ( name ) ;
476
- panel . Children . Add ( contentControl ) ;
477
- mainPanel . Children . Add ( panel ) ;
505
+ //panel.Children.Add(name);
506
+ //panel.Children.Add(contentControl);
507
+ //mainPanel.Children.Add(panel);
508
+ mainPanel . Children . Add ( name ) ;
509
+ mainPanel . Children . Add ( contentControl ) ;
510
+ rowCount ++ ;
478
511
}
479
512
return settingWindow ;
480
513
}
0 commit comments