so i have a button whos XAML is as follows:
<Grid>
<!--MoreCode -->
<Button x:Name="Camera2" Grid.Column="2" Grid.Row="7">
<Grid>
<Image Source="images\tabNormal.png"></Image>
<Image Source="images\OfflineRed_21x76.png" Height="18"
VerticalAlignment="Bottom" Margin="0,0,0,5"></Image>
<TextBlock HorizontalAlignment="Center" Text="Camera 2"
VerticalAlignment="Center"/>
</Grid>
</Button>
<!--MoreCode -->
</Grid>
and it Previews ok.
But when i Run the project I get this:
In the end I will end up making this button a standard control, but i want to understand why it does not seem to build right when I run.
in Closing, the problem seemed to be something with the compiler not referencing the images properly (perhaps because I added the images folder to the project after building everything?), the solution was to add the full path to the images i.e. C:\...folders...\images\filename.png as opposed to the initial images\filename.png once this was done once for one file all files in that folder are readable and you can return to a relitive location. Everything seems to be working fine now even after deleting and re adding the files/folder
Related
This problem does not impact WinForms.
I have downloaded the bare minimum example from the github site:
https://github.com/cefsharp/CefSharp.MinimalExample
As far as I am reasonably aware everything is up-to-date - I have used NuGet to make sure the latest CefSharp.Common, CefSharp.Wpf etc have been installed - currently version 53.
When I use it to browse web pages it's fine. The problem is when I attempt to view a PDF-based page eg:
http://www.cbu.edu.zm/downloads/pdf-sample.pdf
So in the MainWindow.xaml I bind the 'Address' property to this value instead of "www.google.com":
<Window x:Class="CefSharp.MinimalExample.Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
Title="{Binding Path=Title, ElementName=Browser, Converter={StaticResource TitleConverter}}"
WindowState="Maximized">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<wpf:ChromiumWebBrowser Grid.Row="0"
x:Name="Browser"
Address="http://www.cbu.edu.zm/downloads/pdf-sample.pdf" />
<StatusBar Grid.Row="1">
<ProgressBar HorizontalAlignment="Right"
IsIndeterminate="{Binding IsLoading, ElementName=Browser}"
Width="100"
Height="16"
Margin="3" />
<Separator />
<!-- TODO: Could show hover link URL here -->
<TextBlock Text="{Binding Address, ElementName=Browser}"/>
</StatusBar>
</Grid>
When I run the example, in order to navigate to this PDF, the screen remains blank and the progress control does not update:
... unless I do something like un-maximise the browser window, or move it etc, then I can view it:
After this there is another strange problem whereby the scrollbars and +/- buttons appear to be unresponsive. I notice that if I do press the '+' button for example and then another action such as maximize/restore - then the intended '+' action appears to have been carried out. Ditto the scrollbar and other actions.
It does not exhibit this behaviour for the WinForms minimal example, if this helps, only the Wpf.
Any suggestions greatly appreciated.
This has been raised as a duplicate of issue #1799 over at the GitHub site:
WPF/OffScreen PDF Viewer not working #1799
Until Version 55 is released, the solution as stated on the site is:
"Suggested workaround is to call Invalidate() on a timer as proposed on ceforum
You can roll back to 51 and use disable-surfaces or wait for version 55 to be released."
I found that rolling back to a previous version worked for me.
UPDATE 21 Jan 2019
This is no longer an issue with the more recent versions of CefSharp.
I write the following code to show image over the button but when i run the project it is not displaying anything.
<Button x:Name="Employee">
<Button.Template>
<ControlTemplate>
<Border HorizontalAlignment="Center" VerticalAlignment="Center" >
<Image Source="images/Employee.png"
Width="50"
Height="50"/>
</Border>
</ControlTemplate>
</Button.Template>
<TextBlock>Add New Epmloyee</TextBlock>
</Button>
The relative path is correct? The folder "images" must be located in the same folder where the Window's XAML is saved.
Ensure that the Build Action for file "Employee.png" is "Resource".
I just tried your xaml code and it works fine. please make sure that you have images folder under your root directory and an image below it with name employee.png
Finally i nail the problem. The problem was that i create the folder by going directly to project folder through My Computer that's why it was not showing in Visual studio. Now I add the folder from VS and drag the images in it. And Woah! it works fine. Thanks to all of you.
Hi i am Developing a app on universal windows 10 app platform, and when i put some Objects on the XAML window and when change the screen size it's stay how it was before so it's fit the new screen size and if i fix it it's fit the old screen size and i need the app to be universal.
my xaml code:
<Page
x:Class="App17.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App17"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Loaded="Grid_Loaded">
<Grid.Background>
<ImageBrush Stretch="UniformToFill" ImageSource="Assets/backPHONE.jpg"/>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="55*"/>
<RowDefinition Height="9*"/>
</Grid.RowDefinitions>
<RelativePanel>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="41,155,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="128" Width="360" Text="test 123" FontFamily="Century Gothic" FontStretch="UltraExpanded" FontStyle="Italic" FontSize="26" Tapped="textBlock_Tapped" TextAlignment="Center"/>
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" Margin="84,700,0,-666.8" VerticalAlignment="Top" Width="264" SelectionChanged="comboBox_SelectionChanged" Height="32" Grid.Row="1">
<ComboBoxItem Content="test" IsSelected="True"/>
</ComboBox>
<TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Margin="164,675,-2.8,-665" TextWrapping="Wrap" Text="test" VerticalAlignment="Top" Height="20" Width="120" Grid.Row="1" SelectionHighlightColor="#FFF10000" FontFamily="Century Gothic" FontSize="12" FontStretch="UltraExpanded" FontStyle="Italic" Foreground="White"/>
</RelativePanel>
</Grid>
thanks
Let me introduce two possible ways to handle various screen sizes related with Universal Windows 10 Apps.
1. Adaptive Triggers - you can use them to adjut your layout to different device families - for instance you can define how your Page will look on the smartphone and while app is launched on the PC. Below I tried to add some short instructions how you can start using them.
a) When you have Visual Studio opened, please right click on the MainPage.xaml and select "Design in Blend...":
b) Go to "States" tab and select icon (marked red rectangle below) called "Add state group":
c) Now you have to add state, so click the icon next to "Visual State Group" as show below:
d) Now add two state: "Mobile" and "Desktop" as shown below:
e) Last step is to set minimum window width to detect when screen size is changed:
f) Now you are able to set minimum window width for the "Mobile" state:
Please type 320 as below (remember that these are effective pixels not physical)
Once you click "OK" Visual State for "Mobile" will be configured.
Do the same above steps but for "Desktop" state and type 1024 for minimum window width:
Now I can switch between two states and adjust the design for each of them:
(Note that currently selected state is marked with red rectange):
1. Device-Family Folders - you can specify two separate views for Pages but with one code behind. This can help if you have to craft your design specially for mobile devices and for instance fot the PCs.
a) Right click on the project and add new falder called "DeviveFamily-Mobile":
b) Add new Xaml View called the same like your previous page - in my case this is "MainPage":
c) Now you have one code behind class but two separate views that will be applied accordingly to device family:
I hope that it will help you to start.
You can also watch very good Channel9 video or visit my blog where I am trying to present a lot of helpful samples related with UWP.
you must use AdaptiveTriggers
http://www.wintellect.com/devcenter/jprosise/using-adaptivetrigger-to-build-adaptive-uis-in-windows-10
Folks, I am seeing that the below code gives runtime error when I paste it in notepad and save as test.xaml and run it.
<Page xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock Text="Hi Ramakrishnan, good morning"/>
<Button x:Name=”blueButton”
Width=”100”
Height=”40”
Background=”Blue”
Content=”Click Me” />
</Page>
But the below code doesn't give any error but displays the textblock content very correctly in the browser. Any thoughts ? I have also checked including a textbox in place of button above, still same error.
<Page xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock Text="Hi Ramakrishnan, good morning"/>
</Page>
You need to wrap your TextBlock/Button in a StackPanel or other control that allows multiple controls in it's content.
<StackPanel Orientation="Horizontal">
<TextBlock Text="Hi Ramakrishnan, good morning"/>
<Button x:Name="blueButton"
Width="100"
Height="40"
Background="Blue"
Content="Click Me" />
</StackPanel>
Your pasted code is using "smart quotes" instead of "normal quotes" on the button.
<TextBlock Text="Hi Ramakrishnan, good morning"/> <-- normal quotes
<Button x:Name=”blueButton” <-- smart quotes
Have you edited or saved or pasted this through MSWord, perhaps?
(If this isn't the problem then it's possible that what you've pasted in your question isn't exactly what you have in your Xaml file, in which case you should update your question...)
I'm using the following code I found on a question a few hours ago to make a button have an image:
<Button Name="bPlay" Height="70" Width="70" Margin="359,480,349,11">
<Button.Template>
<ControlTemplate>
<Border HorizontalAlignment="Center" VerticalAlignment="Center">
<Image Source="pack://siteoforigin:,,,/Resources/play.bmp" Width="70" Height="70" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
The problem is that for some reason it looks fine on Visual Studio, but when I run the program those buttons won't appear. I can't find the problem and I'm a little bit stuck. The image play.bmp is added to resources obviously, but still I don't know what the problem is, thanks!
"siteoforigin" in the URI indicates the file must be in the given path relative to the directory of the executing assembly. Your executable file is most likely in a bin/Debug folder. It's looking in the subdirectory of the executable, which probably doesn't exist ("bin/Debug/Resources/play.bmp").
If you want to link to the file that way then you have to tell Visual Studio to copy it to the output folder (from the Properties pane). Or copy it yourself.
Or better yet you should link to it as a resource and it will get embedded in the application. Set the file's build type to Resource in the properties pane, and link to it using the relative path in your project folder. In this case, literally write "Resources/play.bmp" in the XAML.
Try simplifying your code, perhaps just pull the image out and see if that displays.
<Button Name="bPlay" Height="70" Width="70" Margin="359,480,349,11">
<Image Source="pack://siteoforigin:,,,/Resources/play.bmp" Width="70" Height="70" />
</Button>
should be valid as well