How to create Application file in xaml????

6 posts, 0 answers
  1. kottu
    kottu avatar
    23 posts
    Member since:
    Mar 2009

    Posted 03 Sep 2009 Link to this post


    I need Connection strings examples in xaml??????????

    anyone can help me !!!!!

    Regards,
    vignesh
  2. Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 09 Sep 2009 Link to this post

    Create normal App.config file and there is a <connectionStrings/> section in it you could use.

    Then in code you use ConfigurationManager class to get the connection string you want.

  3. UI for WPF is Visual Studio 2017 Ready
  4. kottu
    kottu avatar
    23 posts
    Member since:
    Mar 2009

    Posted 10 Sep 2009 Link to this post

    thanks for ur reply ...

    <Application x:Class="wpfsampleapp.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wpfsampleapp="clr-namespace:wpfsampleapp"
        StartupUri="Window1.xaml">
        
        <Application.Resources>
           
       </Application.Resources>
    </Application>

    were to use connection string ......
    send me some examples ......
    regards,
    vignesh


  5. Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 10 Sep 2009 Link to this post

    Add new item -> Application Configuration file   (this is app.config)

    Put:
    <?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
      <connectionStrings> 
        <add name="myConnection" connectionString="Server=(local);Database=Test;Integrated Security=True"/> 
         
      </connectionStrings> 
    </configuration> 

    In there.

    Create Window1.xaml:
    <Window x:Class="WpfApplication4.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="Window1" Height="300" Width="300"
        <Grid> 
            <TextBlock x:Name="txtConn" /> 
        </Grid> 
    </Window> 
     

    in Window1.xaml.cs:

    using System.Configuration; 
    using System.Windows; 
    namespace WpfApplication4 
        /// <summary> 
        /// Interaction logic for Window1.xaml 
        /// </summary> 
        public partial class Window1 : Window 
        { 
            public Window1() 
            { 
                InitializeComponent(); 
                txtConn.Text = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString; 
            } 
        } 
     
    Done.

    This is the way to go. You dont want to embed your connection string in XAML, because you wont be able to change it during runtime if DB has changed etc.
  6. kottu
    kottu avatar
    23 posts
    Member since:
    Mar 2009

    Posted 11 Sep 2009 Link to this post

    Thanks 4 ur reply,

     

    im check ur coding

     Configuration manager is not working .......

     

    help me sir.......

     

     

    regards,

    vignesh

  7. Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 11 Sep 2009 Link to this post

    Add reference to System.Configuration assembly.
Back to Top
UI for WPF is Visual Studio 2017 Ready