How can I put a theme for my WPF SWT program?

I want to use WPF for the Windows version of my Java application. I found this easy to do with SWT, and also supports wpf ResourceDictionary XAML for SWT elements ( see This ). Implementing SWT WPF works well for me, but I couldn't find out how I could post a WPF theme . Some of the SWT widgets are the same org.eclipse.swt.widgets.Button have a setData method, but some of them, like org.eclipse.swt.widgets.Display , do not have this method. Also, the setDate method on the shell will not set the theme in the entire window.

So, how can I put a theme for the whole window of my WPT SWT program?

Here is a sample code:

 import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MenuItem; public class MainForm { protected Shell shell; public static void main(String[] args) { try { MainForm window = new MainForm(); window.open(); } catch (Exception e) { e.printStackTrace(); } } public void open() { Display display = Display.getDefault(); createContents(); shell.open(); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } protected void createContents() { shell = new Shell(); shell.setData( "ResourceDictionary", "ExpressionDark.xaml"); // theme not applied on entire window, just buttons shell.setSize(450, 300); shell.setText("Window Title"); Button button = new Button(shell, SWT.FLAT); button.setText("Button"); button.setSize(250, 50); button.setBounds(0, 50, 250, 50); Menu menu = new Menu(shell, SWT.BAR); shell.setMenuBar(menu); MenuItem mntmNewSubmenu = new MenuItem(menu, SWT.CASCADE); mntmNewSubmenu.setText("New SubMenu"); Menu menu_1 = new Menu(mntmNewSubmenu); mntmNewSubmenu.setMenu(menu_1); } } 
+4
source share
2 answers

SWT WPF is no longer supported. So it’s better not to use it.

+1
source

I have to admit that I didn’t use WPT SWT, so this may not work at all, but this is what you would normally do if you used standard WPF

 <Window .... .... .... ResizeMode="CanResizeWithGrip" Template="{StaticResource WindowTemplateKey}"> </Window> 

Where will you have a template similar to this

 <!-- Custom Window : to allow repositioning of ResizeGrip--> <ControlTemplate x:Key="WindowTemplateKey" TargetType="{x:Type Window}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <Grid> <AdornerDecorator> <ContentPresenter/> </AdornerDecorator> <ResizeGrip Visibility="Collapsed" HorizontalAlignment="Right" x:Name="WindowResizeGrip" Style="{DynamicResource ResizeGripStyle1}" VerticalAlignment="Bottom" IsTabStop="false"/> </Grid> </Border> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="ResizeMode" Value="CanResizeWithGrip"/> <Condition Property="WindowState" Value="Normal"/> </MultiTrigger.Conditions> <Setter Property="Visibility" TargetName="WindowResizeGrip" Value="Visible"/> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> 

So, I assume that you had a window (the shell in your case, specified in a separate ResourceDictionary (XAML file) called "CustomShellTemplateFile.xaml"), you could do something like

shell.setData ("ResourceDictionary", "CustomShellTemplateFile.xaml");

0
source

Source: https://habr.com/ru/post/1401863/


All Articles