Browse Source

updated rendering code to only run if text field is non-empty

master
Claire 2 years ago
parent
commit
0690513c22
  1. 4
      Adaptive Card Editor UWP.sln
  2. 11
      Adaptive Card Editor UWP/Adaptive Card Editor UWP.csproj
  3. 83
      Adaptive Card Editor UWP/MainPage.xaml.cs

4
Adaptive Card Editor UWP.sln

@ -21,7 +21,9 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|Any CPU.ActiveCfg = Debug|x86
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|Any CPU.ActiveCfg = Debug|x64
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|Any CPU.Build.0 = Debug|x64
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|Any CPU.Deploy.0 = Debug|x64
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.ActiveCfg = Debug|ARM
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.Build.0 = Debug|ARM
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.Deploy.0 = Debug|ARM

11
Adaptive Card Editor UWP/Adaptive Card Editor UWP.csproj

@ -12,7 +12,7 @@
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@ -99,6 +99,7 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>false</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
@ -216,6 +217,14 @@
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputPath>bin\Release\</OutputPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

83
Adaptive Card Editor UWP/MainPage.xaml.cs

@ -142,50 +142,57 @@ namespace Adaptive_Card_Editor_UWP
// clear the grid of existing content
grdCard.Children.Clear();
grdTemplated.Children.Clear();
// render an adaptive card
try
// render the adaptive card content
if (txtInput.Text.Length > 0)
{
AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer();
AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(txtInput.Text);
RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard);
grdCard.Children.Add(theCard.FrameworkElement);
}
catch (Exception ex)
{
// this means bad data was ingested by the adaptive card renderer
// so just display the exception details
cardOutput.Text = ex.ToString();
grdCard.Children.Add(cardOutput);
}
// render an adaptive card
try
{
AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer();
AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(txtInput.Text);
RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard);
grdCard.Children.Add(theCard.FrameworkElement);
}
catch (Exception ex)
{
// this means bad data was ingested by the adaptive card renderer
// so just display the exception details
cardOutput.Text = ex.ToString();
grdCard.Children.Add(cardOutput);
}
// render a card using template and data
try
{
string template = txtInput.Text;
string data = txtData.Text;
// render a card using template and data
try
{
string template = txtInput.Text;
string data = txtData.Text;
string rendered = JsonFromTemplate(template, data);
string rendered = JsonFromTemplate(template, data);
// render the card from the rendered template + data
AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer();
AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(rendered);
RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard);
grdTemplated.Children.Add(theCard.FrameworkElement);
}
catch (Exception ex)
{
// render the text as a plain textbox
TextBlock templateOutput = new TextBlock();
templateOutput.TextWrapping = TextWrapping.Wrap;
templateOutput.Padding = new Thickness(10);
templateOutput.Text = txtInput.Text;
// this means bad data was ingested by the adaptive card renderer
// so just display the exception details
templateOutput.Text = ex.ToString();
grdTemplated.Children.Add(templateOutput);
// render the card from the rendered template + data
AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer();
AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(rendered);
RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard);
grdTemplated.Children.Add(theCard.FrameworkElement);
}
catch (Exception ex)
{
// render the text as a plain textbox
TextBlock templateOutput = new TextBlock();
templateOutput.TextWrapping = TextWrapping.Wrap;
templateOutput.Padding = new Thickness(10);
templateOutput.Text = txtInput.Text;
// this means bad data was ingested by the adaptive card renderer
// so just display the exception details
templateOutput.Text = ex.ToString();
grdTemplated.Children.Add(templateOutput);
}
}
// update the XAML layout
grdCard.UpdateLayout();
isRendered = true;

Loading…
Cancel
Save