WPF学习系列 简单的窗体设置
今天要学习的源码是一个窗体设置。效果如下,可拖拽。这让我想起了vs的启动界面
下面是源码的情况
项目结构:
窗体代码:
cs代码
1、新建项目
略
2、设置窗体
AllowsTransparency="True"
WindowStyle="None"
Background="{StaticResource back}"
MouseDown="Window_MouseDown">
只用设置4个属性 AllowsTransparency 设置窗体主体部位支不支持透明
windowstyle 设置窗体的边框样式 为none时没有边框
background设置背景,这一步设置背景图片我不会,先设成蓝色。
mousedown 设置鼠标点击落下后到抬起这一阶段的触发事件
3、拖拽功能(mousedown事件)
private void Window_MouseDown(object sender, MouseButtonEventArgs e) { if(e.ChangedButton==MouseButton.Left)this.DragMove(); }
Window_MouseDown
如果按下的是左键,可以拖拽
先运行一下,效果如下
4.设置背景图片
源码中的设置方法我看不懂,cnblogs-SkyD.xaml文件设计视图也打不开,xmal视图代码如下:
<?xml version="1.0" encoding="utf-8"?> <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <DrawingBrush x:Key="back" Stretch="Uniform"> <DrawingBrush.Drawing> <DrawingGroup> <DrawingGroup.Children> <GeometryDrawing Geometry="F1 M 314,22.1249C 432.672,22.1249 528.875,118.328 528.875,237C 528.875,355.672 432.672,451.875 314,451.875C 195.328,451.875 99.1248,355.672 99.1248,237C 99.1248,118.328 195.328,22.1249 314,22.1249 Z M 314,51.0359C 211.295,51.0359 128.036,134.295 128.036,237C 128.036,339.705 211.295,422.964 314,422.964C 416.705,422.964 499.964,339.705 499.964,237C 499.964,134.295 416.705,51.0359 314,51.0359 Z "> <GeometryDrawing.Pen> <Pen Thickness=" LineJoin="Round" Brush="#27000000"/> </GeometryDrawing.Pen> <GeometryDrawing.Brush> <RadialGradientBrush RadiusX="0.5" RadiusY="0.5" Center="0.5,0.5" GradientOrigin="0.5,0.5"> <RadialGradientBrush.GradientStops> <GradientStop Color="/> <GradientStop Color="#C0FF7B00" Offset="0.52968"/> <GradientStop Color="/> </RadialGradientBrush.GradientStops> <RadialGradientBrush.RelativeTransform> <TransformGroup/> </RadialGradientBrush.RelativeTransform> </RadialGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> <GeometryDrawing Geometry="F1 M 314,75.2265C 403.345,75.2265 475.773,147.655 475.773,237C 475.773,326.345 403.345,398.773 314,398.773C 224.655,398.773 152.226,326.345 152.226,237C 152.226,147.655 224.655,75.2265 314,75.2265 Z "> <GeometryDrawing.Pen> <Pen Thickness=" LineJoin="Round" Brush="#40000000"/> </GeometryDrawing.Pen> <GeometryDrawing.Brush> <RadialGradientBrush RadiusX="0.613236" RadiusY="0.613236" Center="0.349879,0.320823" GradientOrigin="0.349879,0.320823"> <RadialGradientBrush.GradientStops> <GradientStop Color="/> <GradientStop Color="#FFFF7B00" Offset="0.52968"/> <GradientStop Color="/> </RadialGradientBrush.GradientStops> <RadialGradientBrush.RelativeTransform> <TransformGroup/> </RadialGradientBrush.RelativeTransform> </RadialGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> <GeometryDrawing Brush="#4DFFFFFF" Geometry="F1 M 157.841,265.533C 142.319,179.133 199.776,96.5089 286.175,80.9863C 372.575,65.4637 455.199,122.921 470.722,209.321C 478.801,254.288 467.111,298.233 441.861,332.227C 463.016,301.118 472.481,262.027 465.303,222.074C 450.748,141.06 373.274,87.1843 292.26,101.739C 211.246,116.294 157.37,193.768 171.925,274.782C 182.834,335.504 229.091,380.98 285.691,393.823C 222.386,382.241 169.892,332.609 157.841,265.533 Z "/> <GeometryDrawing Brush="#FF7D2500" Geometry="F1 M 159.711,201.088C 157.087,201.784 154.011,202.391 150.484,202.911C 146.958,203.431 142.101,204.247 135.913,205.36C 132.212,205.939 128.786,207.234 125.634,209.247C 122.483,211.259 121.171,214.356 121.698,218.535C 122.983,223.02 125.175,225.092 128.274,224.752C 131.372,224.412 133.686,227.139 135.215,232.934C 136.424,240.111 137.31,250.716 137.873,264.748C 138.435,278.781 138.127,289.269 136.946,296.211C 135.849,299.806 133.934,302.056 131.204,302.962C 128.474,303.868 127.314,306.26 127.724,310.137C 128.364,314.5 131.276,317.005 136.463,317.651C 141.649,318.297 150.21,317.462 162.146,315.146C 166.995,314.526 173.157,312.979 180.631,310.506C 188.105,308.033 191.723,303.905 191.487,298.123C 190.41,294.828 188.268,293.298 185.06,293.533C 181.851,293.768 179.622,291.772 178.372,287.546C 176.32,276.163 175.665,269.193 176.406,266.637C 177.148,264.081 178.341,262.917 179.984,263.144C 183.631,263.169 185.679,265.6 186.129,270.438C 186.579,275.275 189.303,277.58 194.3,277.354C 200.028,275.484 202.986,270.56 203.175,262.582C 203.365,254.605 202.872,248.021 201.696,242.829C 201.163,239.458 199.914,236.045 197.949,232.59C 195.984,229.135 193.105,227.599 189.313,227.983C 184.573,229.47 182.392,232.295 182.772,236.459C 183.151,240.623 181.194,243.406 176.899,244.81C 176.019,245.023 175.246,245.108 174.58,245.062C 173.914,245.017 173.478,244.52 173.271,243.569C 172.924,241.392 172.699,238.405 172.596,234.609C 172.494,230.813 172.457,227.75 172.486,225.421C 172.075,222.597 172.584,220.466 174.014,219.029C 175.444,217.593 179.436,216.287 185.989,215.112C 193.137,214.479 197.742,216.408 199.803,220.899C 201.865,225.389 205.519,227.495 210.766,227.216C 214.542,226.401 217.034,224.612 218.242,221.848C 219.451,219.084 219.713,215.959 219.028,212.473C 218.189,208.142 215.983,203.528 212.41,198.631C 208.836,193.733 204.642,191.477 199.826,191.862C 199.345,192.031 197.891,192.623 195.464,193.637C 193.048,194.514 188.857,195.562 182.891,196.779L 159.711,201.088 Z "> <GeometryDrawing.Pen> <Pen Thickness=" LineJoin="Round" Brush="#FF7D2500"/> </GeometryDrawing.Pen> </GeometryDrawing> <GeometryDrawing Brush="#FF7D2500" Geometry="F1 M 317.536,217.552C 317.431,216.434 317.334,215.089 317.244,213.517C 317.155,211.945 317.019,210.607 316.837,209.503C 316.273,206.881 315.048,205.241 313.161,204.582C 311.273,203.923 309.108,203.849 306.664,204.357C 303.574,204.915 300.001,206.022 295.944,207.68C 291.887,209.338 288.842,211.37 286.811,213.776C 284.356,217.671 283.601,223.653 284.545,231.722C 285.49,239.791 285.269,248.004 283.882,256.363C 283.376,258.611 282.434,261.022 281.055,263.596C 279.676,266.17 277.715,267.789 275.171,268.453C 271.933,268.424 270.107,265.976 269.694,261.107C 269.281,256.239 269.154,252.943 269.311,251.22C 269.305,246.592 269.297,241.225 269.286,235.121C 269.276,229.016 269.004,224.245 268.473,220.808C 267.965,217.857 266.948,215.728 265.422,214.423C 263.897,213.117 261.637,212.738 258.643,213.284C 254.345,214.127 250.127,215.561 245.987,217.585C 241.847,219.608 237.995,221.917 234.431,224.511C 232.012,226.122 229.487,228.328 226.856,231.128C 224.225,233.927 223.072,236.945 223.397,240.179C 223.845,242.153 224.79,243.317 226.231,243.672C 227.672,244.026 229.221,244.093 230.879,243.874C 233.392,243.79 234.877,244.512 235.334,246.04C 235.792,247.568 236.026,249.425 236.039,251.61C 236.326,257.364 236.432,263.229 236.357,269.207C 236.282,275.185 236.649,280.276 237.457,284.482C 239.77,294.667 245.437,299.168 254.46,297.985C 262.762,296.119 269.537,292.513 274.785,287.17C 280.033,281.826 283.556,278.664 285.355,277.682C 287.744,277.844 289.437,279.957 290.432,284.018C 291.427,288.08 294.238,289.984 298.865,289.731C 304.405,288.591 311.071,285.404 318.864,280.171C 326.656,274.938 330.439,269.275 330.213,263.18C 329.861,261.311 329.19,260.27 328.201,260.06C 327.212,259.849 325.828,259.918 324.047,260.268C 320.959,261.034 319.083,259.77 318.418,256.476C 318.043,254.03 317.898,251.541 317.983,249.01L 317.536,217.552 Z "> <GeometryDrawing.Pen> <Pen Thickness=" LineJoin="Round" Brush="#FF7D2500"/> </GeometryDrawing.Pen> </GeometryDrawing> <GeometryDrawing Brush="#FF7D2500" Geometry="F1 M 392.063,233.962C 392.137,238.293 392.142,242.893 392.076,247.762C 392.011,252.631 392.316,257.134 392.993,261.272C 393.692,264.82 395.188,267.289 397.48,268.679C 399.772,270.07 402.634,270.444 406.064,269.803C 411.242,268.796 417.403,265.981 424.547,261.357C 431.692,256.733 435.119,251.441 434.83,245.479C 434.023,242.879 432.511,241.708 430.294,241.967C 428.077,242.225 426.558,241.015 425.736,238.336C 424.998,233.097 424.719,226.519 424.899,218.601C 425.079,210.684 424.765,203.922 423.959,198.315C 422.863,193.4 420.337,189.967 416.383,188.017C 412.428,186.068 408.125,185.516 403.474,186.361C 396.708,188.225 390.955,191.721 386.216,196.849C 381.476,201.977 378.1,205.031 376.087,206.012C 374.029,205.788 372.486,203.648 371.455,199.593C 370.425,195.538 367.708,193.616 363.305,193.828C 359.267,194.699 354.586,196.569 349.261,199.437C 343.936,202.306 339.675,205.132 336.478,207.915C 334.82,209.224 333.296,210.814 331.904,212.685C 330.513,214.556 329.949,216.527 330.213,218.598C 330.667,221.62 332.414,222.898 335.456,222.433L 337.02,222.142C 340.132,221.626 341.894,222.978 342.304,226.198C 343.607,233.627 344.087,242.12 343.743,251.676C 343.4,261.231 343.49,268.283 344.015,272.831C 344.772,276.214 346.395,278.27 348.883,279C 351.372,279.73 354.064,279.707 356.96,278.931C 366.674,276.774 372.875,273.829 375.562,270.095C 378.248,266.362 379.039,260.209 377.935,251.639C 377.186,245.96 377.006,238.938 377.394,230.573C 377.781,222.209 380.663,217.112 386.039,215.285C 387.507,215.046 388.683,215.332 389.568,216.143C 390.453,216.954 391.03,218.087 391.297,219.544L 392.063,233.962 Z "> <GeometryDrawing.Pen> <Pen Thickness=" LineJoin="Round" Brush="#FF7D2500"/> </GeometryDrawing.Pen> </GeometryDrawing> <GeometryDrawing Brush="#FF7D2500" Geometry="F1 M 485.297,224.766C 489.908,220.926 493.953,220.178 497.431,222.523C 500.908,224.868 502.35,228.046 501.756,232.057C 501.162,236.069 498.825,239.613 494.746,242.688C 490.666,245.764 486.82,246.601 483.206,245.2C 479.592,243.799 477.884,241.003 478.082,236.812C 478.281,232.621 480.685,228.606 485.297,224.766 Z M 512.582,146.766C 511.527,151.242 508.59,163.661 503.772,184.021C 498.954,204.381 495.368,214.779 493.014,215.217C 490.66,215.654 489.939,206.04 490.849,186.372C 491.76,166.705 492.472,154.486 492.983,149.714C 493.495,144.942 495.849,140.991 500.044,137.86C 504.24,134.73 507.642,134.308 510.249,136.595C 512.857,138.883 513.634,142.273 512.582,146.766 Z "> <GeometryDrawing.Pen> <Pen Thickness=" LineJoin="Round" Brush="#FF7D2500"/> </GeometryDrawing.Pen> </GeometryDrawing> <GeometryDrawing Geometry="F1 M 158.184,198.688C 155.56,199.384 152.484,199.991 148.957,200.511C 145.431,201.031 140.574,201.847 134.387,202.96C 130.685,203.539 127.259,204.834 124.107,206.847C 120.956,208.859 119.644,211.955 120.171,216.135C 121.457,220.62 123.648,222.692 126.747,222.352C 129.845,222.012 132.159,224.739 133.688,230.534C 134.897,237.711 135.783,248.316 136.346,262.348C 136.908,276.381 136.6,286.868 135.42,293.81C 134.322,297.406 132.407,299.656 129.677,300.562C 126.947,301.468 125.787,303.859 126.198,307.736C 126.837,312.1 129.75,314.605 134.936,315.251C 140.122,315.897 148.683,315.062 160.619,312.746C 165.469,312.126 171.63,310.579 179.104,308.106C 186.578,305.633 190.197,301.505 189.96,295.723C 188.883,292.428 186.741,290.898 183.533,291.133C 180.324,291.368 178.095,289.372 176.845,285.146C 174.793,273.762 174.138,266.793 174.88,264.237C 175.621,261.681 176.814,260.517 178.457,260.744C 182.104,260.769 184.152,263.2 184.602,268.037C 185.053,272.874 187.776,275.18 192.773,274.954C 198.501,273.084 201.459,268.16 201.648,260.182C 201.838,252.205 201.345,245.62 200.169,240.429C 199.636,237.058 198.387,233.645 196.422,230.19C 194.457,226.735 191.578,225.199 187.786,225.583C 183.046,227.069 180.865,229.894 181.245,234.058C 181.625,238.222 179.667,241.006 175.372,242.409C 174.492,242.623 173.719,242.707 173.053,242.662C 172.387,242.617 171.951,242.119 171.744,241.169C 171.397,238.992 171.172,236.005 171.07,232.209C 170.967,228.413 170.93,225.35 170.959,223.021C 170.548,220.197 171.057,218.066 172.487,216.629C 173.917,215.193 177.909,213.887 184.462,212.711C 191.61,212.079 196.215,214.008 198.276,218.499C 200.338,222.989 203.992,225.095 209.24,224.816C 213.015,224.001 215.507,222.212 216.715,219.448C 217.924,216.684 218.186,213.559 217.501,210.073C 216.662,205.742 214.456,201.128 210.883,196.231C 207.309,191.333 203.115,189.077 198.299,189.462C 197.818,189.631 196.364,190.223 193.937,191.236C 191.521,192.114 187.33,193.162 181.364,194.379L 158.184,198.688 Z "> <GeometryDrawing.Pen> <Pen Thickness="1.5" LineJoin="Round" Brush="#FF7D2500"/> </GeometryDrawing.Pen> <GeometryDrawing.Brush> <RadialGradientBrush RadiusX="0.763034" RadiusY="0.592149" Center="0.43784,0.434283" GradientOrigin="0.43784,0.434283"> <RadialGradientBrush.GradientStops> <GradientStop Color="/> <GradientStop Color="/> </RadialGradientBrush.GradientStops> <RadialGradientBrush.RelativeTransform> <TransformGroup/> </RadialGradientBrush.RelativeTransform> </RadialGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> <GeometryDrawing Geometry="F1 M 316.009,215.152C 315.904,214.034 315.807,212.688 315.717,211.117C 315.628,209.545 315.492,208.207 315.31,207.103C 314.746,204.481 313.521,202.841 311.634,202.182C 309.747,201.523 307.581,201.448 305.137,201.957C 302.047,202.515 298.474,203.622 294.417,205.28C 290.36,206.938 287.316,208.97 285.284,211.376C 282.829,215.271 282.074,221.253 283.018,229.322C 283.963,237.39 283.742,245.604 282.355,253.963C 281.85,256.211 280.907,258.622 279.528,261.196C 278.149,263.77 276.188,265.389 273.644,266.053C 270.406,266.024 268.58,263.576 268.167,258.707C 267.754,253.838 267.627,250.543 267.784,248.82C 267.778,244.191 267.77,238.825 267.759,232.721C 267.749,226.616 267.478,221.845 266.946,218.407C 266.438,215.456 265.421,213.328 263.895,212.023C 262.37,210.717 260.11,210.338 257.116,210.884C 252.818,211.727 248.6,213.161 244.46,215.184C 240.32,217.208 236.468,219.517 232.904,222.11C 230.485,223.722 227.96,225.928 225.329,228.728C 222.698,231.527 221.545,234.544 221.87,237.779C 222.318,239.753 223.263,240.917 224.704,241.272C 226.145,241.626 227.694,241.693 229.352,241.474C 231.865,241.39 233.35,242.112 233.807,243.64C 234.265,245.168 234.5,247.025 234.512,249.21C 234.799,254.964 234.906,260.829 234.83,266.807C 234.755,272.784 235.122,277.876 235.93,282.081C 238.243,292.267 243.911,296.768 252.933,295.585C 261.235,293.719 268.01,290.113 273.258,284.77C 278.506,279.426 282.029,276.263 283.828,275.282C 286.217,275.444 287.91,277.556 288.905,281.618C 289.9,285.68 292.711,287.584 297.339,287.331C 302.878,286.191 309.544,283.004 317.337,277.771C 325.129,272.538 328.912,266.875 328.686,260.78C 328.334,258.91 327.663,257.87 326.674,257.659C 325.685,257.449 324.301,257.518 322.52,257.868C 319.433,258.634 317.556,257.37 316.891,254.076C 316.516,251.63 316.371,249.141 316.456,246.61L 316.009,215.152 Z "> <GeometryDrawing.Pen> <Pen Thickness="1.5" LineJoin="Round" Brush="#FF7D2500"/> </GeometryDrawing.Pen> <GeometryDrawing.Brush> <RadialGradientBrush RadiusX="0.592287" RadiusY="0.672395" Center="0.450544,0.443124" GradientOrigin="0.450544,0.443124"> <RadialGradientBrush.GradientStops> <GradientStop Color="/> <GradientStop Color="/> </RadialGradientBrush.GradientStops> <RadialGradientBrush.RelativeTransform> <TransformGroup/> </RadialGradientBrush.RelativeTransform> </RadialGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> <GeometryDrawing Geometry="F1 M 390.536,231.561C 390.61,235.893 390.615,240.493 390.549,245.362C 390.484,250.231 390.789,254.734 391.466,258.872C 392.165,262.42 393.661,264.889 395.953,266.279C 398.245,267.669 401.107,268.044 404.537,267.403C 409.715,266.396 415.876,263.581 423.02,258.957C 430.165,254.333 433.592,249.041 433.303,243.079C 432.496,240.479 430.984,239.308 428.767,239.566C 426.55,239.825 425.031,238.615 424.209,235.935C 423.471,230.697 423.192,224.119 423.372,216.201C 423.552,208.284 423.238,201.522 422.432,195.915C 421.336,191 418.81,187.567 414.856,185.617C 410.901,183.668 406.598,183.115 401.947,183.961C 395.181,185.825 389.428,189.321 384.689,194.449C 379.949,199.577 376.573,202.631 374.56,203.612C 372.502,203.388 370.959,201.248 369.928,197.193C 368.898,193.138 366.181,191.216 361.778,191.428C 357.74,192.299 353.059,194.169 347.734,197.037C 342.409,199.906 338.148,202.731 334.951,205.515C 333.293,206.824 331.769,208.414 330.377,210.285C 328.986,212.156 328.422,214.127 328.686,216.198C 329.14,219.22 330.887,220.498 333.929,220.033L 335.493,219.742C 338.605,219.226 340.367,220.578 340.777,223.798C 342.08,231.227 342.56,239.72 342.216,249.276C 341.873,258.831 341.963,265.883 342.488,270.431C 343.245,273.814 344.868,275.87 347.356,276.6C 349.845,277.329 352.537,277.307 355.433,276.531C 365.147,274.374 371.348,271.429 374.035,267.695C 376.721,263.961 377.512,257.809 376.408,249.238C 375.659,243.56 375.479,236.538 375.867,228.173C 376.254,219.808 379.136,214.712 384.512,212.885C 385.98,212.646 387.156,212.932 388.041,213.743C 388.927,214.554 389.503,215.687 389.77,217.144L 390.536,231.561 Z "> <GeometryDrawing.Pen> <Pen Thickness="1.5" LineJoin="Round" Brush="#FF7D2500"/> </GeometryDrawing.Pen> <GeometryDrawing.Brush> <RadialGradientBrush RadiusX="0.592402" RadiusY="0.66297" Center="0.449238,0.438522" GradientOrigin="0.449238,0.438522"> <RadialGradientBrush.GradientStops> <GradientStop Color="/> <GradientStop Color="/> </RadialGradientBrush.GradientStops> <RadialGradientBrush.RelativeTransform> <TransformGroup/> </RadialGradientBrush.RelativeTransform> </RadialGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> <GeometryDrawing Geometry="F1 M 483.77,222.366C 488.381,218.525 492.426,217.778 495.904,220.123C 499.381,222.467 500.823,225.646 500.229,229.657C 499.635,233.669 497.298,237.213 493.219,240.288C 489.139,243.364 485.293,244.201 481.679,242.8C 478.065,241.399 476.357,238.603 476.555,234.412C 476.754,230.221 479.158,226.206 483.77,222.366 Z M 511.055,144.366C 510,148.842 507.063,161.261 502.245,181.621C 497.427,201.98 493.841,212.379 491.487,212.817C 489.133,213.254 488.412,203.639 489.322,183.972C 490.233,164.305 490.945,152.085 491.456,147.314C 491.968,142.542 494.322,138.591 498.517,135.46C 502.713,132.329 506.115,131.908 508.722,134.195C 511.33,136.483 512.107,139.873 511.055,144.366 Z "> <GeometryDrawing.Pen> <Pen Thickness="1.5" LineJoin="Round" Brush="#FF7D2500"/> </GeometryDrawing.Pen> <GeometryDrawing.Brush> <RadialGradientBrush RadiusX="1.89231" RadiusY="0.597705" Center="0.451968,0.411473" GradientOrigin="0.451968,0.411473"> <RadialGradientBrush.GradientStops> <GradientStop Color="/> <GradientStop Color="/> </RadialGradientBrush.GradientStops> <RadialGradientBrush.RelativeTransform> <TransformGroup/> </RadialGradientBrush.RelativeTransform> </RadialGradientBrush> </GeometryDrawing.Brush> </GeometryDrawing> </DrawingGroup.Children> </DrawingGroup> </DrawingBrush.Drawing> </DrawingBrush> </ResourceDictionary>
cnblogs-SkyD.xaml
感觉太麻烦了,让人望而却步,暂时用图片替代吧,回头再来研究它
但是加图片我也不会,百度一下
看的这篇:http://blog.csdn.net/saloon_yuan/article/details/9137477
简而言之就是下面这样:
关于4、5为什么要这样配置呢,查了下msdn:https://msdn.microsoft.com/zh-cn/library/aa970494(v=vs.110).aspx
没有看懂,但是上面说了,这样可以配置资源文件。就先这样吧。
然后再窗体中加入图片,代码如下:
<Window x:Class="startShow.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title=" AllowsTransparency="True" WindowStyle="None" MouseDown="Window_MouseDown_1" Background="{x:Null}"> <Grid> <Image Source="Resources/bolt_flash.png" Stretch="None"/> </Grid> </Window>
MainWindow.xaml
运行一下:
但是可以看到,我比源码又多拖了一个image控件。而且源码是整个窗体的背景,我设置的是主体部分(不包括标题栏)的背景。
再找找其他方法
这个好像可以:http://www.th7.cn/Article/bc/wpf/201106/20110622080819.html
将Image先注释掉,然后设置图片的属性
测试了下 上面那个方法 生成操作不设置为 Resource 也设置成 内容 也可以运行
然后修改后台代码
public MainWindow() { InitializeComponent(); // 在此点之下插入创建对象所需的代码。 ImageBrush b = new ImageBrush(); b.ImageSource = new BitmapImage(new Uri("Resources/bolt_flash.png", UriKind.RelativeOrAbsolute)); b.Stretch = Stretch.None; this.Background = b; }
构造函数
运行:
成功了。但是还是源文件的那种方式看起更高端一点。麻烦会的人教教我。先放出我的代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace startShow { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); // 在此点之下插入创建对象所需的代码。 ImageBrush b = new ImageBrush(); b.ImageSource = new BitmapImage(new Uri("Resources/bolt_flash.png", UriKind.RelativeOrAbsolute)); b.Stretch = Stretch.None; this.Background = b; } private void Window_MouseDown_1(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) this.DragMove();//如果是左键 拖动 } } }
MainWindow.xaml.cs
<Window x:Class="startShow.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title=" AllowsTransparency="True" WindowStyle="None" MouseDown="Window_MouseDown_1" Background="{x:Null}"> <Grid> <!--<Image Source="Resources/bolt_flash.png" Stretch="None"/>--> </Grid> </Window>
MainWindow.xaml
WPF学习系列 简单的窗体设置的更多相关文章
- Android+Jquery Mobile学习系列(6)-个人信息设置
本节开始,进行代码的实战练习.我的这个App是管理保险客户信息的,数据采用Sqlite存储在本地手机上,第一次使用需要先登记自己的个人信息,这个功能非常简单,也无关紧要,我是拿这个练手,方便做后面复杂 ...
- 【WPF学习笔记】之如何设置下拉框读取SqlServer数据库的值:动画系列之(一)
先前条件:设置好数据库,需要三个文件CommandInfo.cs.DbHelperSQL.cs.myHelper.cs,需要修改命名空间,参照之前随笔http://www.cnblogs.com/Ow ...
- WPF学习系列 游戏-选张图片做成9宫格拼图
今天要学习一个拼图项目. 目标是传入一张图片,然后将它分成9份,去掉一份,鼠标点击进行拼图. 源文件结构很简单 第一步.新建项目 这一步没什么好说的,新建一个项目就跟源文件结构一样了 第二步.页面布局 ...
- WPF学习系列 绘制旋转的立方体
我是一年经验的web程序员,想学习一下wpf,比较喜欢做项目来学习,所以在网上找了一些项目,分析代码,尽量能够做到自己重新敲出来 第一个项目是 中间的方块会不停的旋转. 第一步,新建wpf项目 第二步 ...
- WPF学习系列之八(形状,画刷和变换)
形状,画刷和变换 概述: 在许多用户界面技术中,普通控件和自定义绘图之间具有清晰的区别.通常来说,绘图特性只用于特定的应用程序--如游戏,数据可视化和物理仿真等.而WPF具有一个非常不同的原则.它 ...
- WPF学习系列之七 (样式与行为)
样式(Styles)是组织和重用格式化选项的重要工具.不是使用重复的标记填充XAML,以设置诸如边距.颜色及字体等细节,而可以创建一系列封装所有这些细节的样式.然后可以在需要之处通过一个属性应用样式. ...
- WPF学习系列之六 (元素绑定)
元素绑定 简单地说,数据绑定是一种关系,该关系告诉WPF从一个源对象提取一些信息,并使用这些信息设置目标对象的属性.目标属性总是依赖属性,并且通常位于WPF元素中. 一.将元素绑定到一起 <Wi ...
- WPF学习系列之五(WPF控件)
控件: 1.内容控件------这些控件能够包含嵌套的元素,为它们提供几乎无限的显示能力.内容控件包括Lable,Button 以及ToolTip类. 内容控件是更特殊的控件类型,它们可以包含( ...
- WPF学习系列之四(WPF事件5大类)
WPF最重要的5类事件: 生命周期事件:这些事件将在元素被初始化,加载或卸载时发生. 鼠标事件 这些事件是鼠标动作的结果. 键盘事件 这些事件是键盘动作的结果. 手写笔事件 这些事件是作用类似铅笔的手 ...
随机推荐
- Java - 网络编程
Java的网络编程学习,关于计算机基础的学习参考:计算机网络基础学习 - sqh. 参考:
- Json CPP 中文支持与入门示例
在每一个Json Cpp自带*.cpp文件头加上: #include "stdafx.h" 将Json Cpp对自带的头文件的引用修改为单引号方式,例如json_reader.cp ...
- iOS 学习 - 2.据网址显示源码
输入网址,解出源码,显示label 我这里是在第二个界面显示的,用的属性传值. A界面先从 storyboard 拖个 textfield 和一个 button .m里面button的方法 //按钮点 ...
- Java web会话简单应用
Java会话主要分为两块:Cookie和HttpSessionCookie技术:会话数据保存在浏览器客户端.Session技术:会话数据保存在服务器端.一.下面介绍一下Cookie的应用1. Cook ...
- Oracle汉字转拼音package
--函数GetHzFullPY(string)用于获取汉字字符串的拼音 --select GetHzFullPY('中华人民共和国') from dual; --返回:ZhongHuaRenMinGo ...
- (八)数据呈现——一图胜千言<完结>
数据分析师就像厨师一样.厨师的工作有5步:下单.备料.切配.烹饪.打荷.数据分析师的工作也有5步.呈现数据就好像打荷.厨师在把菜肴端给客人之前要做盘饰美化,让菜肴精致美观,这个工作就是打荷.同样,数据 ...
- iOS实现渐变色背景(两种方式实现)
之前做过类似的功能,现在记录一下,来来来... 效果图: 说明=========================== 方法1: 说明:无返回值 用法:直接调用方法.原理是在view的layer层添加. ...
- request.getContextPath()报错
别人的项目,刚用MyEclipse加载进来,一大堆错误(见怪不怪了) JSP报错,上图: 报错:“The method getContextPath() from the type HttpServl ...
- Windows操作系统下远程连接MySQL数据库
用Eclipse做一个后台项目,但是数据库不想放在本地电脑,于是买了一个腾讯云服务器(学生有优惠,挺便宜的),装上MySQL数据库,但是测试连接的时候,发现总是连接不是上,但是本地数据库可以连接,于是 ...
- BZOJ 1862: [Zjoi2006]GameZ游戏排名系统 [treap hash]
1862: [Zjoi2006]GameZ游戏排名系统 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1318 Solved: 498[Submit][ ...