简体   繁体   中英

How can i use xaml in asp.net website project

Can I use a XAML file in a ASP.NET project. For example, when I open localhost/tryconnect.aspx , I want to see XAML file. Is it possible?

MainWindows.xaml code:

<Window x:Class="TFSMove.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="http://schemas.microsoft.com/netfx/2009/xaml/presentation"
        x:Name="_MainWindow" Width="500" Height="450" 
        Title="Move TFS Work Items" >
    <Window.Resources>
        <local:AndConverter x:Key="AndConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid Grid.Row="0" Grid.ColumnSpan="3" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
                <Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Margin="5" Content="TFS Server:"/>
            <TextBox x:Name="_TFSServer" Grid.Row="0" Grid.Column="1" Margin="5" TextChanged="_TFSServer_TextChanged" >
                <TextBox.Resources>
                    <VisualBrush x:Key="hint" TileMode="None" Opacity="0.4" Stretch="None" AlignmentX="Left">
                        <VisualBrush.Transform>
                            <TranslateTransform X="5" Y="0" />
                        </VisualBrush.Transform>
                        <VisualBrush.Visual>
                            <Grid>
                                <TextBox BorderThickness="0" FontStyle="Italic" Foreground="Black" Text="&lt;Enter the URL to the TFS project server.&gt;"/>
                            </Grid>
                        </VisualBrush.Visual>
                    </VisualBrush>
                </TextBox.Resources>
                <TextBox.Style>
                    <Style TargetType="TextBox">
                        <Style.Triggers>
                            <Trigger Property="Text" Value="{x:Null}">
                                <Setter Property="Background" Value="{StaticResource hint}" />
                            </Trigger>
                            <Trigger Property="Text" Value="">
                                <Setter Property="Background" Value="{StaticResource hint}" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TextBox.Style>
            </TextBox>
            <Button x:Name="_BtnMove" Grid.Row="0" Grid.Column="2" Margin="5" Click="_BtnMoveClick" Content="¡Move!">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource AndConverter}" Mode="OneWay">
                        <Binding ElementName="_From_Project" Path="Text" Mode="OneWay"/>
                        <Binding ElementName="_To_Areas" Path="SelectedItem" Mode="OneWay"/>
                        <Binding ElementName="_To_Iterations" Path="SelectedItem" Mode="OneWay"/>
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>

            <Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" Margin="5" >SQL Connection:</Label>
            <TextBox x:Name="_SQLConnection" Grid.Row="1" Grid.Column="1" MinWidth="100" Margin="5" >
                <TextBox.Resources>
                    <VisualBrush x:Key="hint" TileMode="None" Opacity="0.4" Stretch="None" AlignmentX="Left">
                        <VisualBrush.Transform>
                            <TranslateTransform X="5" Y="0" />
                        </VisualBrush.Transform>
                        <VisualBrush.Visual>
                            <Grid>
                                <TextBox BorderThickness="0" FontStyle="Italic" Foreground="Black" Text="&lt;Enter the SQL Connection String to the TFL Server SQL database.&gt;"/>
                            </Grid>
                        </VisualBrush.Visual>
                    </VisualBrush>
                </TextBox.Resources>
                <TextBox.Style>
                    <Style TargetType="TextBox">
                        <Style.Triggers>
                            <Trigger Property="Text" Value="{x:Null}">
                                <Setter Property="Background" Value="{StaticResource hint}" />
                            </Trigger>
                            <Trigger Property="Text" Value="">
                                <Setter Property="Background" Value="{StaticResource hint}" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TextBox.Style>
            </TextBox>
            <Button x:Name="_BtnSQL" Grid.Row="1" Grid.Column="2" Margin="5" Click="_BtnSQLTestClick" IsEnabled="{Binding ElementName=_SQLConnection, Path=Text.Length}" >¡Test!</Button>

            <Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Margin="5" >Query:</Label>
            <TextBox x:Name="_WorkItemQuery" Grid.Row="2" Grid.Column="1" MinWidth="100" Margin="5" >
                <TextBox.Resources>
                    <VisualBrush x:Key="hint" TileMode="None" Opacity="0.4" Stretch="None" AlignmentX="Left">
                        <VisualBrush.Transform>
                            <TranslateTransform X="5" Y="0" />
                        </VisualBrush.Transform>
                        <VisualBrush.Visual>
                            <Grid>
                                <TextBox BorderThickness="0" FontStyle="Italic" Foreground="Black" Text="&lt;Enter the WorkItem Number or Query for moving.&gt;"/>
                            </Grid>
                        </VisualBrush.Visual>
                    </VisualBrush>
                </TextBox.Resources>
                <TextBox.Style>
                    <Style TargetType="TextBox">
                        <Style.Triggers>
                            <Trigger Property="Text" Value="{x:Null}">
                                <Setter Property="Background" Value="{StaticResource hint}" />
                            </Trigger>
                            <Trigger Property="Text" Value="">
                                <Setter Property="Background" Value="{StaticResource hint}" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TextBox.Style>
            </TextBox>
            <Button x:Name="_BtnQuery" Grid.Row="2" Grid.Column="2" Margin="5" Click="_BtnQueryClick" IsEnabled="{Binding ElementName=_WorkItemQuery, Path=Text.Length}">Search</Button>
        </Grid>
        <GridSplitter Grid.Column="1" Grid.Row="2" ShowsPreview="True" VerticalAlignment="Stretch"  Width="6" HorizontalAlignment="Center" Margin="0,0,0,0" />
        <RichTextBox x:Name="_WorkItemDisplay" Grid.Row="2" Grid.Column="0" Margin="5" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
            <RichTextBox.Resources>
                <Style TargetType="{x:Type Paragraph}">
                    <Setter Property="Margin" Value="0" />
                </Style>
            </RichTextBox.Resources>
        </RichTextBox>
        <Grid Grid.Row="1" Grid.Column="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition/>
            </Grid.RowDefinitions>
            <GroupBox Grid.Row="0" FontSize="16" Margin="5,0,5,5">
                <GroupBox.Header>From</GroupBox.Header>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <TextBlock x:Name="_From_Project" Grid.Row="0" Margin="5,0,5,0" TextWrapping="WrapWithOverflow" />
                </Grid>
            </GroupBox>
            <Rectangle Grid.Row="1" Margin="1" SnapsToDevicePixels="True" Height="1" Width="Auto" Fill="Black" />
            <GroupBox Grid.Row="2" FontSize="16" Margin="5,0,5,5">
                <GroupBox.Header>To</GroupBox.Header>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Label Grid.Row="0" Margin="5,0,5,0" FontSize="{Binding ElementName=_BtnMove, Path=FontSize}" Content="Project:"/>
                    <ComboBox x:Name="_To_Projects" Grid.Row="1" Margin="5,0,5,5" FontSize="{Binding ElementName=_BtnMove, Path=FontSize}" SelectionChanged="_To_Projects_SelectionChanged" />
                    <Label Grid.Row="2" Margin="5,0,5,0" FontSize="{Binding ElementName=_BtnMove, Path=FontSize}" Content="Area:"/>
                    <ComboBox x:Name="_To_Areas" Grid.Row="3" Margin="5,0,5,5" FontSize="{Binding ElementName=_BtnMove, Path=FontSize}" SelectionChanged="UpdateMoveEnabled" />
                    <Label Grid.Row="4" Margin="5,0,5,0" FontSize="{Binding ElementName=_BtnMove, Path=FontSize}" Content="Iteration:"/>
                    <ComboBox x:Name="_To_Iterations" Grid.Row="5" Margin="5,0,5,5" FontSize="{Binding ElementName=_BtnMove, Path=FontSize}"  SelectionChanged="UpdateMoveEnabled"/>
                </Grid>
            </GroupBox>

        </Grid>
    </Grid>
</Window>

MainWindow.xaml.cs code:

 namespace TFSMove
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static DependencyProperty MoveEnabledProperty = DependencyProperty.Register("MoveEnabled", typeof(bool), typeof(MainWindow), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
        public bool? MoveEnabled
        {
            get
            {
                return GetValue(MoveEnabledProperty) as bool?;
            }
            set { SetValue(MoveEnabledProperty, value); }
        }

        public static DependencyProperty TFS_ServerProperty = DependencyProperty.Register("TFS_Server", typeof(Uri), typeof(MainWindow), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
        private Uri TFS_Server
        {
            get
            {
                return
                    GetValue(TFS_ServerProperty) as Uri;
            }
            set { SetValue(TFS_ServerProperty, value); }
        }

        public static DependencyProperty TFS_WorkItemsProperty = DependencyProperty.Register("TFS_WorkItems", typeof(WorkItemCollection), typeof(MainWindow), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
        private WorkItemCollection TFS_WorkItems
        {
            get
            {
                return GetValue(TFS_WorkItemsProperty) as WorkItemCollection;
            }
            set { SetValue(TFS_WorkItemsProperty, value); }
        }

        private DispatcherTimer _tfs_server_text_changed_timer;

        public MainWindow()
        {
            InitializeComponent();
            _BtnQuery.IsEnabled = false;
        }

        private void _TFSServer_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (_tfs_server_text_changed_timer == null)
            {
                _tfs_server_text_changed_timer = new DispatcherTimer();
                _tfs_server_text_changed_timer.Tag = sender;
                _tfs_server_text_changed_timer.Tick += _TFSServer_PostTextChanged;
            }

            _tfs_server_text_changed_timer.Interval = TimeSpan.FromMilliseconds(750);
            _tfs_server_text_changed_timer.Start();

            e.Handled = true;
        }

        private void _TFSServer_PostTextChanged(object sender, EventArgs e)
        {
            (sender as DispatcherTimer).Stop();
            TextBox tb = (sender as DispatcherTimer).Tag as TextBox;
            if (sender.Equals(_tfs_server_text_changed_timer))
            {
                _tfs_server_text_changed_timer.Tag = null;
                _tfs_server_text_changed_timer = null;
            }

            TfsTeamProjectCollection TPC = null;
            Uri tfs_server_ = null;

            if (Uri.TryCreate(tb.Text, UriKind.Absolute, out tfs_server_))
            {
                TFS_Server = tfs_server_;
                try
                {
                    TPC = new TfsTeamProjectCollection(TFS_Server);
                }

                catch (Exception ex)
                {
                    Paragraph p = new Paragraph(new Run(ex.InnerException == null ? ex.Message : ex.InnerException.Message));
                    p.Foreground = Brushes.Red;
                    _WorkItemDisplay.Document.Blocks.Add(p);
                    _BtnQuery.IsEnabled = false;
                    return;
                }
            }

            else
                TFS_Server = null;

            if (TPC == null)
            {
                _WorkItemDisplay.AppendText(".");
                _BtnQuery.IsEnabled = false;
                return;
            }

            Cursor saved_cursor = this.Cursor;
            this.Cursor = Cursors.Wait;

            //!?this._To_Projects.SelectedValuePath = "Id";
            this._To_Projects.DisplayMemberPath = "Name";
            this._To_Projects.ItemsSource = TPC.GetService<WorkItemStore>().Projects;

            _WorkItemDisplay.Document.Blocks.Add(new Paragraph(new Run("Connected to: " + tb.Text)));
            _BtnQuery.IsEnabled = true;

            this.Cursor = saved_cursor;
        }

        private void _To_Projects_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_To_Projects.SelectedItem == null)
            {
                _To_Areas.ItemsSource = null;
                _To_Iterations.ItemsSource = null;
            }

            else
            {
                Cursor saved_cursor = this.Cursor;
                this.Cursor = Cursors.Wait;

                //!?_To_Areas.SelectedValuePath = "Id";
                _To_Areas.DisplayMemberPath = "Name";
                _To_Areas.ItemsSource = (_To_Projects.SelectedItem as Project).AreaRootNodes;

                //!?_To_Iterations.SelectedValuePath = "Id";
                _To_Iterations.DisplayMemberPath = "Name";
                _To_Iterations.ItemsSource = (_To_Projects.SelectedItem as Project).IterationRootNodes;

                this.Cursor = saved_cursor;
            }
        }

        private void _BtnQueryClick(object sender, RoutedEventArgs e)
        {
            StringBuilder wiquery = new StringBuilder(this._WorkItemQuery.Text);
            int work_item_number = 0;
            if (int.TryParse(this._WorkItemQuery.Text, out work_item_number))
            {
                wiquery.Clear();
                wiquery.Append("SELECT * FROM WorkItems WHERE [System.Id] = '");
                wiquery.Append(work_item_number.ToString());
                wiquery.Append("'");
            }

            Cursor saved_cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            _WorkItemDisplay.Document.Blocks.Clear();
            try
            {
                TfsTeamProjectCollection TPC = new TfsTeamProjectCollection(TFS_Server);
                TPC.EnsureAuthenticated();
                TFS_WorkItems = TPC.GetService<WorkItemStore>().Query(wiquery.ToString());

                switch (TFS_WorkItems.Count)
                {
                    case 0:
                        _WorkItemDisplay.Document.Blocks.Add(new Paragraph(new Run("No items were returned from search.")));
                        _From_Project.Text = string.Empty;
                        break;

                    case 1:
                        {
                            Table t = new Table();
                            GridLengthConverter lc = new GridLengthConverter();
                            t.Columns.Add(new TableColumn() { Width = (GridLength)lc.ConvertFromString("*") });
                            t.Columns.Add(new TableColumn() { Width = (GridLength)lc.ConvertFromString("3*") });

                            TableRowGroup rg = new TableRowGroup();
                            TableRow r = new TableRow();
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["ID"].Name))));
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["ID"].Value.ToString()))));
                            rg.Rows.Add(r);
                            r = new TableRow();
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["Title"].Name))));
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["Title"].Value.ToString()))));
                            rg.Rows.Add(r);
                            r = new TableRow();
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["Area Path"].Name))));
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["Area Path"].Value.ToString()))));
                            rg.Rows.Add(r);
                            r = new TableRow();
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["Iteration Path"].Name))));
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["Iteration Path"].Value.ToString()))));
                            rg.Rows.Add(r);

                            _From_Project.Text = TFS_WorkItems[0].Fields["Team Project"].Value.ToString();

                            foreach (Field f in TFS_WorkItems[0].Fields)
                            {
                                if (f.Value != null)
                                {
                                    string value = f.Value.ToString();
                                    if (!string.IsNullOrWhiteSpace(value))
                                    {
                                        r = new TableRow();

                                        r.Cells.Add(new TableCell(new Paragraph(new Run(f.Name))));
                                        r.Cells.Add(new TableCell(new Paragraph(new Run(value))));

                                        rg.Rows.Add(r);
                                    }
                                }
                            }
                            t.RowGroups.Add(rg);

                            _WorkItemDisplay.Document.Blocks.Add(t);
                        }
                        break;

                    default:
                        {
                            Table t = new Table();
                            GridLengthConverter lc = new GridLengthConverter();
                            t.Columns.Add(new TableColumn() { Width = (GridLength)lc.ConvertFromString("*") });
                            t.Columns.Add(new TableColumn() { Width = (GridLength)lc.ConvertFromString("7*") });

                            TableRowGroup rg = new TableRowGroup();
                            TableRow r = new TableRow();

                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["ID"].Name)) { FontWeight = FontWeights.Bold }));
                            r.Cells.Add(new TableCell(new Paragraph(new Run(TFS_WorkItems[0].Fields["Title"].Name)) { FontWeight = FontWeights.Bold }));

                            rg.Rows.Add(r);

                            _From_Project.Text = TFS_WorkItems[0].Fields["Team Project"].Value.ToString();

                            foreach (WorkItem wi in TFS_WorkItems)
                            {
                                r = new TableRow();
                                r.Cells.Add(new TableCell(new Paragraph(new Run(wi.Fields["ID"].Value.ToString()))));
                                r.Cells.Add(new TableCell(new Paragraph(new Run(wi.Fields["Title"].Value.ToString()))));
                                rg.Rows.Add(r);
                            }

                            t.RowGroups.Add(rg);

                            _WorkItemDisplay.Document.Blocks.Add(t);
                        }
                        break;
                }
            }

            catch (Exception ex)
            {
                _WorkItemDisplay.Document.Blocks.Add(new Paragraph(new Run(ex.InnerException == null ? ex.Message : ex.InnerException.Message)) { Foreground = Brushes.Red });
                _From_Project.Text = string.Empty;
            }

            this.Cursor = saved_cursor;
        }

        private void _BtnMoveClick(object sender, RoutedEventArgs e)
        {
            Cursor saved_cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            _WorkItemDisplay.Document.Blocks.Clear();
            _From_Project.Text = string.Empty;
            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection(_SQLConnection.Text);
                conn.Open();

                if (TFS_WorkItems.Count == 0)
                {
                    _WorkItemDisplay.Document.Blocks.Add(new Paragraph(new Run("Nothing to move.")) { Foreground = Brushes.Red });
                }

                else
                {
                    TfsTeamProjectCollection TPC = new TfsTeamProjectCollection(TFS_Server);
                    TPC.EnsureAuthenticated();

                    WorkItemStore WIS = TPC.GetService<WorkItemStore>();
                    StringBuilder sql_command_are = new StringBuilder();
                    StringBuilder sql_command_latest = new StringBuilder();
                    StringBuilder sql_command_were = new StringBuilder();

                    foreach (WorkItem wi in TFS_WorkItems)
                    {
                        sql_command_are.Clear();
                        sql_command_latest.Clear();
                        sql_command_were.Clear();

                        sql_command_are.Append("UPDATE [WorkItemsAre] SET AreaID='");
                        sql_command_latest.Append("UPDATE [WorkItemsLatest] SET AreaID='");
                        sql_command_were.Append("UPDATE [WorkItemsWere] SET AreaID='");

                        sql_command_are.Append((_To_Areas.SelectedItem as Node).Id.ToString());
                        sql_command_latest.Append((_To_Areas.SelectedItem as Node).Id.ToString());
                        sql_command_were.Append((_To_Areas.SelectedItem as Node).Id.ToString());

                        sql_command_are.Append("', IterationID='");
                        sql_command_latest.Append("', IterationID='");
                        sql_command_were.Append("', IterationID='");

                        sql_command_are.Append((_To_Iterations.SelectedItem as Node).Id.ToString());
                        sql_command_latest.Append((_To_Iterations.SelectedItem as Node).Id.ToString());
                        sql_command_were.Append((_To_Iterations.SelectedItem as Node).Id.ToString());

                        sql_command_are.Append("' WHERE ID='");
                        sql_command_latest.Append("' WHERE ID='");
                        sql_command_were.Append("' WHERE ID='");

                        sql_command_are.Append(wi.Id.ToString());
                        sql_command_latest.Append(wi.Id.ToString());
                        sql_command_were.Append(wi.Id.ToString());

                        sql_command_are.Append("'");
                        sql_command_latest.Append("'");
                        sql_command_were.Append("'");

                        new SqlCommand(sql_command_are.ToString(), conn).ExecuteNonQuery();
                        new SqlCommand(sql_command_latest.ToString(), conn).ExecuteNonQuery();
                        new SqlCommand(sql_command_were.ToString(), conn).ExecuteNonQuery();

                        _WorkItemDisplay.Document.Blocks.Add(new Paragraph(new Run("Moved " + wi.Id.ToString() + " to " + (_To_Projects.SelectedItem as Project).Name)));
                    }
                }
            }

            catch (Exception ex)
            {
                _WorkItemDisplay.Document.Blocks.Add(new Paragraph(new Run(ex.InnerException == null ? ex.Message : ex.InnerException.Message)) { Foreground = Brushes.Red });
                _From_Project.Text = string.Empty;
            }

            finally
            {
                if (conn != null)
                    conn.Close();
            }

            this.Cursor = saved_cursor;
        }

        private void UpdateMoveEnabled(object sender, SelectionChangedEventArgs e)
        {
            BindingOperations.GetMultiBindingExpression(_BtnMove, Button.IsEnabledProperty).UpdateTarget();
        }

        private void _BtnSQLTestClick(object sender, RoutedEventArgs e)
        {
            Cursor saved_cursor = this.Cursor;
            this.Cursor = Cursors.Wait;
            _WorkItemDisplay.Document.Blocks.Clear();

            try
            {
                SqlConnection conn = new SqlConnection(_SQLConnection.Text);
                conn.Open();
                SqlCommand sql_cmd = new SqlCommand("SELECT COUNT(*) FROM [WorkItemsAre]", conn);
                int wi_count = (int)sql_cmd.ExecuteScalar();
                conn.Close();

                _WorkItemDisplay.Document.Blocks.Add(new Paragraph(new Run("Success! " + wi_count.ToString() + " work items counted.")));
            }

            catch (Exception ex)
            {
                _WorkItemDisplay.Document.Blocks.Add(new Paragraph(new Run(ex.InnerException == null ? ex.Message : ex.InnerException.Message)) { Foreground = Brushes.Red });
            }

            this.Cursor = saved_cursor;
        }
    }

    public class AndConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parm, System.Globalization.CultureInfo culture)
        {
            switch (targetType.Name)
            {
                case "Boolean":
                case "Nullable`1":
                    {
                        for (int i = 0; i < values.Count(); i++)
                        {
                            if (values[i] == null)
                                return false;

                            switch (values[i].GetType().Name)
                            {
                                case "Boolean":
                                case "Nullable`1":
                                    if (values[i] as bool? ?? false)
                                        continue;
                                    return false;

                                case "String":
                                case "string":
                                    if (string.IsNullOrWhiteSpace(values[i] as string))
                                        return false;

                                    else if ("0".CompareTo(values[i] as string) == 0 || "false".CompareTo((values[i] as string).ToLower()) == 0)
                                        return false;
                                    break;

                                case "Node":
                                    if ((values[i] as Node).Id > 0)
                                        continue;
                                    return false;

                                default:
                                    throw new NotImplementedException("Cannot process input type " + values[i].GetType().Name);
                            }
                        }

                        return true;
                    }

                default:
                    throw new NotImplementedException("Cannot process output type " + targetType.Name);
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parm, System.Globalization.CultureInfo culture)
        {
            object[] ret = new object[targetTypes.Count()];
            for (int i = 0; i < targetTypes.Count(); i++)
                ret[i] = System.Convert.ChangeType(value, targetTypes[i]);

            return ret;
        }
    }
}

You can use XAML in Silverlight

Questions on stackoverflow about silverlight: https://stackoverflow.com/search?q=siverlight

The structure is equals to WPF but some features are different between they

If you want to run native WPF applications you would need to consider creating a XBAP application like Glen said. Note that XBAP application support in modern day browsers is rare to find today and can be limited.

If you want to use XAML controls/files in your ASP.NET website, you will need to write a Silverlight application first, and then add the control to your website. Note that some browsers are even discontinuing support for Silverlight applications

Reference materials

The best way to use XAML in a web application is to use Silverlight. Using Silverlight is not a great idea for any project at this point.

Extended support for Silverlight ends 10/12/2021, which makes it seem like Silverlight should be around for ahwile, right? Wrong. In order to run a Silverlight application on the web, you'll need a browser that supports it. Chrome won't support Silverlight after September. Firefox is making users jump through hoops if they want to run the Silverlight plugin. And under Windows 10, the user has to be running IE11, Edge won't run Silverlight apps.

XAML on the web is dead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM