I'm creating an app who is a list of choices. For the 3 first choices I want to put 3 images an bellow them 3 radiobutton.
but it only show images when I write :
<Grid>
<Image x:Name="sinus" Source="C:\Users\Maximilien\Documents\BFH\HBridge\HBridge\Resources\sin1.bmp" HorizontalAlignment="Left" Height="100" Margin="120,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<Image x:Name="triangle" Source="C:\Users\Maximilien\Documents\BFH\HBridge\HBridge\Resources\tri1.bmp" HorizontalAlignment="Left" Height="100" Margin="320,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<Image x:Name="continue" Source="C:\Users\Maximilien\Documents\BFH\HBridge\HBridge\Resources\cont1.bmp" HorizontalAlignment="Left" Height="100" Margin="520,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<RadioButton x:Name="sinus_checkbox" HorizontalAlignment="Left" Margin="173,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Sinusoïdale" IsChecked="True"/>
<RadioButton x:Name="triangle_checkbox" HorizontalAlignment="Left" Margin="373,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Triangulaire"/>
<RadioButton x:Name="continue_checkbox" HorizontalAlignment="Left" Margin="573,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Continue"/>
but when I send the .exe to a friend the 3 images wouldn't display..
I've tried this :
<Grid>
<Image x:Name="sinus" Source="pack://siteoforigin:,,,/Resources/sin1.bmp" HorizontalAlignment="Left" Height="100" Margin="120,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<Image x:Name="triangle" Source="pack://siteoforigin:,,,/Resources/tri1.bmp" HorizontalAlignment="Left" Height="100" Margin="320,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<Image x:Name="continue" Source="pack://siteoforigin:,,,/Resources/cont1.bmp" HorizontalAlignment="Left" Height="100" Margin="520,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<RadioButton x:Name="sinus_checkbox" HorizontalAlignment="Left" Margin="173,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Sinusoïdale" IsChecked="True"/>
<RadioButton x:Name="triangle_checkbox" HorizontalAlignment="Left" Margin="373,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Triangulaire"/>
<RadioButton x:Name="continue_checkbox" HorizontalAlignment="Left" Margin="573,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Continue"/>
But with that , the 3 images won't even display on my PC and in the debug I got something like : Cannot find a part of the path 'C:\Users\Maximilien\Documents\BFH\HBridge\HBridge\bin\Debug\Resources\sin1.bmp'.
Maybe it's a problem with Ressources but I've set thoses images in the .resx
Thank for answer , I use VS2012 ultimate
Sorry for my english
P.S : some screen :
http://i.stack.imgur.com/8qM82.png
.rar of my project :
http://www.partage-facile.com/V0SQ3J1CU7/hbridge.rar.html
You can try using relative path (relative to your project folder) instead of absolute path like C:\... Assuming that your project folder is C:\Users\Maximilien\Documents\BFH\HBridge\HBridge, this is the relative path to your images :
<Image x:Name="sinus" Source="Resources\sin1.bmp" ..... />
<Image x:Name="triangle" Source="Resources\tri1.bmp" ..... />
<Image x:Name="continue" Source="Resources\cont1.bmp" ..... />
you can also rely on Visual Studio's intellisense to get the correct relative path. When typing Source="" in XAML, with cursor positioned between double-quotes press CTRL+SPACE, dropdown will appear suggesting available paths (tested in VS2012 here)
Related
I have .xaml items accross three files. In one .xaml I have option to change language at running.
Is there any chance how can I access items from others .xaml to change the language as well?
Changing language of .xaml items in MainWindow.xaml.cs
public partial class MainWindow : Window
{
string strLanguage = "";
Boolean boolInit = true;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Set_Language();
}
private void ddlLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Set_Language();
}
private void Set_Language()
{
if (boolInit == false)
{
strLanguage = "SMS_Vrana.Languages." + ((ComboBoxItem)ddlLanguage.SelectedItem).Name.ToString();
ResourceManager LocRM = new ResourceManager(strLanguage, typeof(MainWindow).Assembly);
lblNumber.Text = LocRM.GetString("strNumber");
lblMessage.Text = LocRM.GetString("strMessage");
btnSend.Content = LocRM.GetString("strSend");
menuItemFile.Header = LocRM.GetString("strMenuFile");
menuItemMainMenu.Header = LocRM.GetString("strMenuMainMenu");
menuItemClose.Header = LocRM.GetString("strMenuClose");
menuItemCheckConnection.Header = LocRM.GetString("strMenuConnection");
}
}
.xaml of Mainwindow.xaml:
<grid>
<Menu DockPanel.Dock="Top" Margin="0,0,0,434">
<MenuItem Header="_File" Name="menuItemFile">
<MenuItem Header="_Main Menu" Click="MenuItem_Click" Name="menuItemMainMenu"/>
<Separator/>
<MenuItem Header="Close" Click="MenuItem_Close" Name="menuItemClose"/>
</MenuItem>
<MenuItem Header="Monitoring" IsEnabled="False">
<MenuItem Header="Ping" IsCheckable="True" Checked="menuPingCheck" Unchecked="menuPingUncheck"/>
<MenuItem Header="GSM" IsCheckable="True" Checked="menuGsmCheck" Unchecked="menuGsmUncheck"/>
</MenuItem>
<MenuItem Header="Check Connection" Click="menuItemCheckConnection_Click" Name="menuItemCheckConnection"/>
<ComboBox x:Name="ddlLanguage" SelectionChanged="ddlLanguage_SelectionChanged" Height="23" Width="80">
<ComboBoxItem IsEnabled="False" IsSelected="True" Content="Language"/>
<ComboBoxItem x:Name="English" Content="English"/>
<ComboBoxItem x:Name="Czech" Content="Cesky"/>
</ComboBox>
<MenuItem Header="_Language" x:Name="menuLangTest" IsEnabled="True" Visibility="Hidden">
<MenuItem Header="Czech" x:Name="menuCzech" Checked="menuItemCzechCheck" Unchecked="menuItemCzechUnche"/>
<MenuItem Header="English" x:Name="menuEng" Checked="menuItemEngCheck" Unchecked="menuItemEngUnche"/>
</MenuItem>
</Menu>
<Ellipse Fill="#000000" Stroke="#000000" Margin="10,0,0,347" x:Name="ellGSM" HorizontalAlignment="Left" Width="38" Height="38" VerticalAlignment="Bottom" Visibility="Hidden"/>
<Ellipse Fill="#000000" Stroke="#000000" Margin="204,0,0,347" Name="ellCol" HorizontalAlignment="Left" Width="38" Height="38" VerticalAlignment="Bottom" Visibility="Hidden"/>
<TextBox x:Name="txtNumber" MaxLength="13" HorizontalAlignment="Left" Height="26" TextWrapping="Wrap" VerticalAlignment="Top" Width="310" Margin="10,153,0,0" PreviewTextInput="txtNumber_PreviewTextInput"/>
<TextBox x:Name="txtMessage" MaxLength="1300" HorizontalAlignment="Left" Height="100" TextWrapping="Wrap" VerticalAlignment="Top" Width="310" Margin="10,250,0,0"/>
<Button x:Name="btnSend" Cursor="Hand" Content="Send!" HorizontalAlignment="Left" VerticalAlignment="Top" Width="310" Margin="10,407,0,0" Height="52" FontSize="36" Click="btnSend_Click"/>
<TextBlock Grid.Column="0" Name="lblNumber" Text="Number" Margin="10,122,213,321" FontSize="16"/>
<TextBlock Grid.Row="0" Grid.Column="0" Name="lblMessage" Text="Message" Margin="10,217,213,224" FontSize="16"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="GSM" VerticalAlignment="Top" Margin="53,46,0,0" Name="txtblockGsm" Visibility="Hidden"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="PING" VerticalAlignment="Top" Margin="172,46,0,0" Name="txtblockPing" Visibility="Hidden"/>
<Image HorizontalAlignment="Left" Name="imgGsm" Height="42" VerticalAlignment="Top" Width="49" Margin="271,40,0,0" Source="C:\Users\lvrabel\source\repos\SMS Vrána\SMS Vrána\Images\GsmGreen.png" Visibility="Hidden"/>
<Label Content="1300" HorizontalAlignment="Left" Margin="287,345,0,0" VerticalAlignment="Top" Height="25" Name="lblLeftCharacters" />
<Label Content="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="280,84,0,0" Name="lblGsmSignal" Width="40"/>
</grid>
.xaml of Authentication.xaml what I would like to access in MainWindow.xaml.cs for changing language for that items as well. I just would like to change language in whole application and no just for one window.
<Grid Margin="0,-17,0,0">
<Menu DockPanel.Dock="Top" Margin="0,17,0,432">
<MenuItem Header="File" FontSize="16" Name="menuItemFile">
<MenuItem Header="Back on Main Menu" Click="menuItemMainMenuClick"/>
<Separator/>
<MenuItem Header="Close" Click="menuItemCloseClick"/>
</MenuItem>
</Menu>
<Label Content="IP Adress" Name="lblIPAddress" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,210,0,0" Height="36" Width="101" FontSize="16"/>
<Label Content="Login" Name="lblLogin" HorizontalAlignment="Left" Margin="10,279,0,0" VerticalAlignment="Top" Height="31" Width="59" FontSize="16"/>
<Label Content="Password" Name="lblPassword" HorizontalAlignment="Left" Margin="10,343,0,0" VerticalAlignment="Top" Height="31" Width="75" FontSize="16"/>
<TextBox HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="292" Margin="10,251,0,0" Name="txtBoxIP" PreviewTextInput="txtBoxIP_PreviewTextInput"/>
<TextBox HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="292" Margin="10,315,0,0" Name="txtBoxLogin"/>
<PasswordBox HorizontalAlignment="Left" VerticalAlignment="Top" Width="292" Margin="10,379,0,0" PasswordChar="*" Name="pswBox" Height="23" />
<CheckBox Content="Remember me!" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,413,0,0" Name="CheckBoxRemCredts" Checked="CheckBoxRemCredts_Checked"/>
<Button Content="Login" Cursor="Hand" HorizontalAlignment="Left" Height="34" Margin="10,442,0,0" VerticalAlignment="Top" Width="292" Name="btnLoginAuth" Click="btnLoginAuth_Click" FontSize="18"/>
</Grid>
U can access the xaml code of any xaml until and unless they are in same project and same solution.
U just need to initialize the other xaml you want to use in your xaml.cs file.
For example, I have two xaml files Main.xaml and Login.xaml
So i can use Login view and its element in Main.xaml.cs
Syntax :
Main.xaml.cs
Login login=new Login();
Now you can access any control of Login page provided u give name to every element you use.
eg : login.TextBlockEmail.Text="yourtext";
UPDATED ANSWER :
Hi, I got what you are looking for. Your whole idea is to achieve Localization where all your views associated with the main view shall update.
There are multiple approaches to achieve this, here i am sharing links which may help you :
https://www.codeproject.com/Articles/22967/WPF-Runtime-Localization
https://www.codeproject.com/Articles/35159/WPF-Localization-Using-RESX-Files
https://social.msdn.microsoft.com/Forums/vstudio/en-US/4a7f049b-f1b7-4982-874f-f9ecfe3d9140/how-to-change-the-language-in-my-view-wpf?forum=wpf
c# - localization - changing language in wpf app
What you ask for is possible - surely you can get reference to some control in the backend file (.xaml.cs) and then assign it to some variable that is visible to both classes.
However this is better done by using events. You define some event on your main class that should be visible to every window, and then subscribe to it in the code for each window.
I am building an application in WIndows phone 7. I have the following xaml:
<Rectangle Fill="White" HorizontalAlignment="Left" Height="123" Margin="273,173,0,0"
Stroke="Black" VerticalAlignment="Top" Width="172" RadiusX="20" RadiusY="20 />
Now here i want to insert a text and also make this clickable in order to navigate to a new page. How to do this. Please share some code
<Rectangle Fill="White" HorizontalAlignment="Left" Height="123" Margin="273,173,0,0"
Stroke="Black" VerticalAlignment="Top" Width="172" RadiusX="20" RadiusY="20"
MouseDown="SomeFunctionInCodeBehindToTakeYouToANewPage" />
<TextBlock HorizontalAlignment="Left" IsHitTestVisible="False" Margin="340,222,0,0"
VerticalAlignment="Top" Text="I Like Pie" />
Hi all,
I found an issue with textblock in my Silverlight application. As observed from the picture I attached, in the "How to play" silverlight page, the title are bound to disappear if I navigate from different route.
Please note that that is static textblock with static wording. Just that from different navigation point, the header wording is missing!
I navigate from screen to screen using this.content = new something; (e.g. : this.content = new instruction())
Can someone guide me on how to overcome this issue? All my page is not usercontrol, but just silverlight page.
<navigation:Page x:Class="SpotTheDifference.UI.Game.Silverlight.instruction"
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"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="893" d:DesignHeight="670"
Title="BonusLink Spot 'd' Difference">
<Grid x:Name="LayoutRoot">
<Image x:Name="imgBG" HorizontalAlignment="Left" Height="670" VerticalAlignment="Top" Width="893" Source="/img/bg/dialogbox-bg.jpg" Visibility="Visible"/>
<Image x:Name="imgPlayGame" HorizontalAlignment="Left" Height="50" Margin="731,209,0,0" VerticalAlignment="Top" Width="145" Source="/img/btn/btn_play_red.png"/>
<Button x:Name="btnPlay" Content="" HorizontalAlignment="Left" Margin="731,209,0,0" VerticalAlignment="Top" Width="145" Height="50" Opacity="0" Click="btnPlay_Click" MouseEnter="btnPlay_MouseEnter" MouseLeave="btnPlay_MouseLeave"/>
<Image x:Name="imgScoreBoard" HorizontalAlignment="Left" Height="50" Margin="731,264,0,0" VerticalAlignment="Top" Width="145" Source="/img/btn/btn_scoreboard_red.png"/>
<Button x:Name="btnScoreBoard" Content="" HorizontalAlignment="Left" Margin="731,264,0,0" VerticalAlignment="Top" Width="145" Height="50" Opacity="0" Click="btnScoreBoard_Click" MouseEnter="btnScoreBoard_MouseEnter" MouseLeave="btnScoreBoard_MouseLeave"/>
<Image x:Name="imgProfile" HorizontalAlignment="Left" Height="50" Margin="731,319,0,0" VerticalAlignment="Top" Width="145" Source="/img/btn/btn_profile_red.png"/>
<Button x:Name="btnProfile" Content="" HorizontalAlignment="Left" Margin="731,319,0,0" VerticalAlignment="Top" Width="145" Height="50" Opacity="0" Click="btnProfile_Click" MouseEnter="btnProfile_MouseEnter" MouseLeave="btnProfile_MouseLeave"/>
<Image x:Name="imgHowToPlay" HorizontalAlignment="Left" Height="50" Margin="731,374,0,0" VerticalAlignment="Top" Width="145" Source="/img/btn/btn_howto_green.png"/>
<Image x:Name="imgLogOut" HorizontalAlignment="Left" Height="50" Margin="731,429,0,0" VerticalAlignment="Top" Width="145" Source="/img/btn/btn_logout_red.png"/>
<Button x:Name="btnLogOut" Content="" HorizontalAlignment="Left" Margin="731,429,0,0" VerticalAlignment="Top" Width="145" Height="50" Opacity="0" Click="btnLogOut_Click" MouseEnter="btnLogOut_MouseEnter" MouseLeave="btnLogOut_MouseLeave"/>
<TextBlock x:Name="lblDesc" HorizontalAlignment="Left" Margin="145,250,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="505" Height="195" Foreground="#FF007EFF" FontFamily="Comic Sans MS" FontSize="14.667" FontWeight="Bold">
<Run Text="There will be a set of 2 almost identical pictures revealed every month for players to identify 10 differences each."/>
<LineBreak/>
<Run/>
<LineBreak/>
<Run Text="With every correct click, a circle will appear on the difference spot; whereas every wrong click, the timer will be further reduced."/>
<LineBreak/>
<Run/>
<LineBreak/>
<Run Text="Total play time for this game is 30 seconds."/>
<LineBreak/>
<Run Text="(Hint: The faster you identify the differences, the higher the score)"/>
</TextBlock>
<TextBlock x:Name="lblHeader" Text="Spot 'd' Difference: How to Play Instruction" Margin="146,214,275,427" FontFamily="Comic Sans MS" FontSize="21.333" FontWeight="Bold" Width="472" Height="29" />
</Grid>
this code converts any controls or object to xml
if I saved this
the saved xml would be looks like:
<Grid Name="g" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Image Source="pack://application:,,,/WpfApplication1;component/Images/Picture3.jpg" Stretch="Fill" Name="image1" Width="200" Height="150" Margin="96,36,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
<Button Name="button1" Width="75" Height="23" Margin="352,71,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">Button</Button>
<TextBox Name="textBox1" Width="120" Height="23" Margin="62,198,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" xml:space="preserve" />
<Label Name="label1" Height="28" Margin="270,213,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">Label</Label>
</Grid>
I used this code to save this:
System.IO.StreamWriter s = new System.IO.StreamWriter(#"d:\grid.xml");
s.WriteLine(System.Windows.Markup.XamlWriter.Save(g));
s.Close();
g is the name of the grid which contains all controls
my question:
can I reverse this, read this xml file and represent it on a window
Just use the XAML Reader Class.
var somecontrol = XamlReader.Load(#"<ItemsPanelTemplate
xmlns=""http://schemas.microsoft.com/client/2007""
xmlns:toolkit=""http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"">
<toolkit:WrapPanel /></ItemsPanelTemplate>");
I am using a rectangle and putting emotion images in it, and i want to do is if I make the rectangle hidden, the emotion images in it should be hidden.
I am attaching an image for help in it.
Please let me know which property should I use for getting this, in Windows Forms if we use panel, this can be done automatically. But in WPF C#, this is not done automatically.
Here is the code
<Rectangle Grid.ColumnSpan="2" Height="71" HorizontalAlignment="Left" Margin="226,262,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="192" Fill="#B5101010" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="229,266,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="28" Source="/WPFTEST;component/Images/emo/emotion_evilgrin.png" MouseUp="image1_MouseUp_1" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="264,266,0,0" Name="image2" Source="/WPFTEST;component/Images/emo/emotion_grin.png" Stretch="Fill" VerticalAlignment="Top" Width="28" MouseUp="image2_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="34,299,0,0" Name="image4" Source="/WPFTEST;component/Images/emo/emotion_tongue.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image4_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="68,266,0,0" Name="image5" Source="/WPFTEST;component/Images/emo/emotion_suprised.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image5_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="34,266,0,0" Name="image6" Source="/WPFTEST;component/Images/emo/emotion_smile.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image6_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="0,266,0,0" Name="image7" Source="/WPFTEST;component/Images/emo/emotion_happy.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image7_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="0,299,0,0" Name="image8" Source="/WPFTEST;component/Images/emo/emotion_wink.png" Stretch="Fill" VerticalAlignment="Top" Width="28" Grid.Column="1" MouseUp="image8_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="230,299,0,0" Name="image9" Source="/WPFTEST;component/Images/emo/emotion_unhappy.png" Stretch="Fill" VerticalAlignment="Top" Width="28" MouseUp="image9_MouseUp" Visibility="Hidden" />
<Image Height="27" HorizontalAlignment="Left" Margin="265,299,0,0" Name="image10" Source="/WPFTEST;component/Images/emo/emotion_waii.png" Stretch="Fill" VerticalAlignment="Top" Width="28" MouseUp="image10_MouseUp" Visibility="Hidden" />
I know that it is not under the rectangle tag, but if i add images under rectangle tag then it causes error.
Thanks
Atif
If those icons are part of the "rectangle" which should be an ItemsControl or panel of some sort, the icons will hide if the parent container is hidden (Visibility = Visibility.Hidden/Collapsed).
Edit: The images are not part of the rectangle they are just placed on top using horrible margin abusing code.
There is no relationship between the rectangle and the icons. As i said, the icons need to be added as children of a container. (e.g. ItemsControl with WrapPanel as ItemsPanel) Surely winforms would not hide the icons either if they are not part of an owning container...
If you want to leave your code as is and not have to change those margins you can just bind the Visibility property of the icons to the Visibility property of the rectangle.
Visibility="{Binding Visibility, ElementName=rectangle2}"